• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <atomic>

    std::atomic_ref::load

    T
      load(memory_order order = memory_order_seq_cst) const noexcept; // (1) C++20
    constexpr value_type
      load(memory_order order = memory_order_seq_cst) const noexcept; // (1) C++26
    

    概要

    値を読み込む

    事前条件

    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

    処理系

    参照