最終更新日時(UTC):
が更新

履歴 編集

function
<atomic>

std::atomic_flag::notify_all(C++20)

void notify_all() volatile noexcept;
void notify_all() noexcept;

概要

待機している全てのスレッドを起床させる。

この関数は、wait()関数によるブロッキング待機を解除する。

効果

起床待機している全てのアトミックオブジェクトの待機を解除する

戻り値

なし

例外

投げない

#include <iostream>
#include <atomic>
#include <thread>

int main()
{
  std::atomic_flag x = ATOMIC_FLAG_INIT;

  auto f = [&x] {
    while (true) {
      x.wait(false);
      if (x.test()) {
        break;
      }
    }
  };

  std::thread t1 {f};
  std::thread t2 {f};

  x.clear();
  x.notify_all();

  t1.join();
  t2.join();
}

出力

バージョン

言語

  • C++20

処理系

  • Clang: (9.0時点で実装なし)
  • GCC: (9.2時点で実装なし)
  • Visual C++: (2019 Update 3時点で実装なし)

参照