Skip to content

Latest commit

 

History

History
75 lines (54 loc) · 1.49 KB

File metadata and controls

75 lines (54 loc) · 1.49 KB

atomic_exchange

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

概要

shared_ptrオブジェクトを、アトミックに入れ替える。

要件

p != nullptrであること。

戻り値

atomic_exchange_explicit(p, r, memory_order_seq_cst)
  • atomic_exchange_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> a(new int(1));
  std::shared_ptr<int> b(new int(2));

  std::shared_ptr<int> prev_state = std::atomic_exchange(&a, b);

  std::cout << *a << std::endl;
  std::cout << *prev_state << std::endl;
}
  • std::atomic_exchange[color ff0000]

出力

2
1

バージョン

言語

  • C++11

処理系

参照