Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 2.02 KB

atomic_compare_exchange_strong.md

File metadata and controls

85 lines (64 loc) · 2.02 KB

atomic_compare_exchange_strong

  • memory[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template<class T>
  bool atomic_compare_exchange_strong(
         shared_ptr<T>* p, shared_ptr<T>* expected, shared_ptr<T> desired);
}

概要

強い比較で、アトミックにshared_ptrオブジェクトを入れ替える。

要件

  • p != nullptrであること。
  • expected != nullptrであること。

戻り値

atomic_compare_exchange_strong_explicit(
  p,
  expected,
  desired,
  memory_order_seq_cst,
  memory_order_seq_cst)
  • atomic_compare_exchange_strong_explicit[link atomic_compare_exchange_strong_explicit.md]
  • memory_order_seq_cst[link /reference/atomic/memory_order.md]

例外

投げない

#include <iostream>
#include <memory>

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

  std::shared_ptr<int> ps = p;
  std::shared_ptr<int> q(new int(3));
  std::atomic_compare_exchange_strong(&p, &ps, std::move(q));

  std::shared_ptr<int> result = std::atomic_load(&p);
  std::cout << *result << std::endl;
}
  • std::atomic_compare_exchange_strong[color ff0000]
  • std::move[link /reference/utility/move.md]
  • std::atomic_load[link atomic_load.md]

出力

3

バージョン

言語

  • C++11

処理系

参照