std::atomic_...<std::shared_ptr>
Defined in header <memory>
|
||
template< class T > bool atomic_is_lock_free( const std::shared_ptr<T>* p ); |
(1) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > std::shared_ptr<T> atomic_load( const std::shared_ptr<T>* p ); |
(2) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > std::shared_ptr<T> atomic_load_explicit |
(3) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > void atomic_store( std::shared_ptr<T>* p, std::shared_ptr<T> r ); |
(4) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > void atomic_store_explicit |
(5) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > std::shared_ptr<T> atomic_exchange |
(6) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > std::shared_ptr<T> atomic_exchange_explicit |
(7) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > bool atomic_compare_exchange_weak |
(8) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > bool atomic_compare_exchange_strong |
(9) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > bool atomic_compare_exchange_strong_explicit |
(10) | (since C++11) (deprecated in C++20) (removed in C++26) |
template< class T > bool atomic_compare_exchange_weak_explicit |
(11) | (since C++11) (deprecated in C++20) (removed in C++26) |
If multiple threads of execution access the same std::shared_ptr object without synchronization and any of those accesses uses a non-const member function of shared_ptr
then a data race will occur unless all such access is performed through these functions, which are overloads of the corresponding atomic access functions (std::atomic_load, std::atomic_store, etc.).
Note that the control block of a shared_ptr
is thread-safe: different std::shared_ptr objects can be accessed using mutable operations, such as operator= or reset
, simultaneously by multiple threads, even when these instances are copies, and share the same control block internally.
(p, expected, desired, std::memory_order_seq_cst,
std::memory_order_seq_cst).
(p, expected, desired, std::memory_order_seq_cst,
std::memory_order_seq_cst).
- If they are equivalent (store the same pointer value, and either share ownership of the same object or are both empty), assigns desired into *p using the memory ordering constraints specified by success and returns true.
- If they are not equivalent, assigns *p into *expected using the memory ordering constraints specified by failure and returns false.
atomic_compare_exchange_weak_explicit
may fail spuriously.If p is a null pointer, the behaviors of these functions are all undefined.
Contents |
[edit] Parameters
p, expected | - | a pointer to a std::shared_ptr |
r, desired | - | a std::shared_ptr |
mo, success, failure | - | memory ordering selectors of type std::memory_order |
[edit] Exceptions
These functions do not throw exceptions.