namespace std {
template <class T>
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order order);
}
概要
メモリオーダーを指定して、shared_ptr
オブジェクトを、アトミックに読み込む。
要件
p != nullptr
であること。
order
が以下のメモリオーダーではないこと:
戻り値
*p
相当のことをアトミックに実行して返す。
例外
投げない
例
#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;
}
出力
3
バージョン
言語
- C++11
処理系
- Clang: 3.3
- GCC: 5.0
- ICC: ??
- Visual C++: 2012, 2013