Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 2.03 KB

atomic_store_explicit.md

File metadata and controls

85 lines (60 loc) · 2.03 KB

atomic_store_explicit

  • memory[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template<class T>
  void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order order);
}
  • memory_order[link /reference/atomic/memory_order.md]

概要

メモリオーダーを指定して、shared_ptrオブジェクトに、アトミックに値を書き込む。

要件

p != nullptrであること。

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

効果

p->swap(r)相当のことを、アトミックに実行する。

戻り値

なし

例外

投げない

#include <iostream>
#include <memory>

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

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

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

出力

3

バージョン

言語

  • C++11

処理系

参照