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

履歴 編集

function template
<memory>

std::atomic_store(C++11)

namespace std {
  template <class T>
  void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
}

概要

shared_ptrオブジェクトに、アトミックに値を書き込む。

要件

p != nullptrであること。

効果

戻り値

なし

例外

投げない

#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;
}

出力

3

バージョン

言語

  • C++11

処理系

参照