- atomic[meta header]
- std[meta namespace]
- atomic_ref[meta class]
- function[meta id-type]
- cpp20[meta cpp]
void notify_all() const noexcept; // (1) C++20
constexpr void notify_all() const noexcept; // (1) C++20
待機している全てのスレッドを起床させる。
この関数は、wait()
関数によるブロッキング待機を解除する。
- C++26 :
is_const_v
<T>
がfalse
であること
起床待機している全てのアトミックオブジェクトの待機を解除する
なし
投げない
#include <iostream>
#include <atomic>
#include <thread>
int main()
{
bool x = false;
auto f = [&x] {
std::atomic_ref r{x};
while (true) {
r.wait(false);
if (r.load() == true) {
break;
}
}
};
std::thread t1 {f};
std::thread t2 {f};
std::atomic_ref{x}.store(true);
std::atomic_ref{x}.notify_all();
t1.join();
t2.join();
}
- notify_all()[color ff0000]
- load[link load.md]
- store[link store.md]
- wait[link wait.md]
- C++20
- Clang: 9.0 [mark noimpl]
- GCC: 9.2 [mark noimpl]
- Visual C++: 2019 Update 3 [mark noimpl]
- P0514R4 Efficient concurrent waiting for C++20
- ogiroux/atomic_wait - Sample implementation of C++20 atomic_wait/notify
- P1643R1 Add wait/notify to
atomic_ref
- P1960R0 NB Comment Changes Reviewed by SG1
- 宣言に
const
を追加
- 宣言に
- P3323R1 cv-qualified types in
atomic
andatomic_ref
- C++26でCV修飾されたテンプレート引数を受け取れるようになった
- P3309R3
constexpr atomic
andatomic_ref
- C++26で
constexpr
に対応した
- C++26で