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

履歴 編集

function
<atomic>

std::atomic_ref::load(C++20)

T load(memory_order order = memory_order_seq_cst) const noexcept;

概要

値を読み込む

要件

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

効果

orderで指定されたメモリオーダーにしたがって、値を読み込む

戻り値

*thisが参照するオブジェクトをアトミックに読み込んで返す

例外

投げない

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

int main()
{
  int value = 3;
  std::atomic_ref<int> x{value};

  std::thread t{[&x]{
    int n = x.load();
    std::cout << n << std::endl;
  }};
  t.join();
}

出力

3

バージョン

言語

  • C++20

処理系