namespace std {
void
atomic_flag_notify_all(
volatile atomic_flag* object) const noexcept; // (1) C++20
void
atomic_flag_notify_all(
atomic_flag* object) const noexcept; // (2) C++20
constexpr void
atomic_flag_notify_all(
atomic_flag* object) const noexcept; // (2) C++26
}
概要
待機している全てのスレッドを起床させる。
この関数は、atomic_flag_wait()
関数によるブロッキング待機を解除する。
効果
起床待機している全てのアトミックオブジェクトの待機を解除する
戻り値
なし
例外
投げない
例
#include <iostream>
#include <atomic>
#include <thread>
int main()
{
std::atomic_flag x = ATOMIC_FLAG_INIT;
auto f = [&x] {
while (true) {
std::atomic_flag_wait(&x, false);
if (std::atomic_flag_test(&x)) {
break;
}
}
};
std::thread t1 {f};
std::thread t2 {f};
std::atomic_flag_clear(&x);
std::atomic_flag_notify_all(&x);
t1.join();
t2.join();
}
xxxxxxxxxx
#include <iostream>
#include <atomic>
#include <thread>
int main()
{
std::atomic_flag x = ATOMIC_FLAG_INIT;
auto f = [&x] {
while (true) {
std::atomic_flag_wait(&x, false);
if (std::atomic_flag_test(&x)) {
break;
}
}
};
std::thread t1 {f};
std::thread t2 {f};
std::atomic_flag_clear(&x);
std::atomic_flag_notify_all(&x);
t1.join();
t2.join();
}
出力
バージョン
言語
- C++20
処理系
- Clang: 9.0 ❌
- GCC: 9.2 ❌
- Visual C++: 2019 Update 3 ❌