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

履歴 編集

function
<atomic>

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

bool
  test(memory_order order = memory_order::seq_cst
      ) const volatile noexcept;                  // (1) C++20

bool
  test(memory_order order = memory_order::seq_cst
       ) const noexcept;                          // (2) C++20
constexpr bool
  test(memory_order order = memory_order::seq_cst
       ) const noexcept;                          // (2) C++26

概要

現在の値をbool値として取得する。

要件

orderが以下のメモリオーダーではないこと:

効果

order値によってメモリに影響がある

戻り値

アトミックに読み込まれた*thisが指している値を返す

例外

投げない

#include <iostream>
#include <atomic>

int main()
{
  std::cout << std::boolalpha;

  std::atomic_flag x = ATOMIC_FLAG_INIT;
  std::cout << x.test() << std::endl;

  x.test_and_set();
  std::cout << x.test() << std::endl;
}

出力

false
true

バージョン

言語

  • C++20

処理系

参照