Skip to content

Latest commit

 

History

History
77 lines (56 loc) · 1.58 KB

atomic_load.md

File metadata and controls

77 lines (56 loc) · 1.58 KB

atomic_load

  • memory[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template <class T>
  shared_ptr<T> atomic_load(const shared_ptr<T>* p);
}

概要

shared_ptrオブジェクトを、アトミックに読み込む。

要件

p != nullptrであること。

戻り値

atomic_load_explicit(p, memory_order_seq_cst)
  • atomic_load_explicit[link atomic_load_explicit.md]
  • memory_order_seq_cst[link /reference/atomic/memory_order.md]

例外

投げない

#include <iostream>
#include <memory>

int main()
{
  std::shared_ptr<int> p;

  // pにxをアトミックに書き込む
  std::shared_ptr<int> x(new int(3));
  std::atomic_store(&p, x);

  // pが指すshared_ptrオブジェクトを、アトミックに読み込む
  std::shared_ptr<int> result = std::atomic_load(&p);
  std::cout << *result << std::endl;
}
  • std::atomic_load[color ff0000]
  • std::atomic_store[link atomic_store.md]

出力

3

バージョン

言語

  • C++11

処理系

参照