std::atomic_...<std::shared_ptr>
Declarations
// 1)
template< class T >
bool atomic_is_lock_free( const std::shared_ptr<T>* p );
// 2)
template< class T >
std::shared_ptr<T> atomic_load( const std::shared_ptr<T>* p );
// 3)
template< class T >
std::shared_ptr<T> atomic_load_explicit( const std::shared_ptr<T>* p,
std::memory_order mo );
// 4)
template< class T >
void atomic_store( std::shared_ptr<T>* p,
std::shared_ptr<T> r );
// 5)
template< class T >
void atomic_store_explicit( std::shared_ptr<T>* p,
std::shared_ptr<T> r,
std::memory_order mo);
// 6)
template< class T >
std::shared_ptr<T> atomic_exchange( std::shared_ptr<T>* p,
std::shared_ptr<T> r);
// 7)
template<class T>
std::shared_ptr<T> atomic_exchange_explicit( std::shared_ptr<T>* p,
std::shared_ptr<T> r,
std::memory_order mo);
// 8)
template< class T >
bool atomic_compare_exchange_weak( std::shared_ptr<T>* p,
std::shared_ptr<T>* expected,
std::shared_ptr<T> desired);
// 9)
template<class T>
bool atomic_compare_exchange_strong( std::shared_ptr<T>* p,
std::shared_ptr<T>* expected,
std::shared_ptr<T> desired);
// 10)
template< class T >
bool atomic_compare_exchange_strong_explicit( std::shared_ptr<T>* p,
std::shared_ptr<T>* expected,
std::shared_ptr<T> desired,
std::memory_order success,
std::memory_order failure);
// 11)
template< class T >
bool atomic_compare_exchange_weak_explicit( std::shared_ptr<T>* p,
std::shared_ptr<T>* expected,
std::shared_ptr<T> desired,
std::memory_order success,
std::memory_order failure);
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.
Determines whether atomic access to the shared pointer pointed-to by p
is lock-free.
Equivalent to atomic_load_explicit(p, std::memory_order_seq_cst)
Returns the shared pointer pointed-to by p
. As with the non-specialized std::atomic_load_explicit
, mo
cannot be std::memory_order_release
or std::memory_order_acq_rel
Equivalent to atomic_store_explicit(p, r, memory_order_seq_cst)
Stores the shared pointer r
in the shared pointer pointed-to by p
atomically, effectively executing p->swap(r)
.
As with the non-specialized std::atomic_store_explicit
, mo
cannot be std::memory_order_acquire
or std::memory_order_acq_rel
.
Equivalent to atomic_exchange_explicit(p, r, memory_order_seq_cst)
Stores the shared pointer r
in the shared pointer pointed to by p
and returns the value formerly pointed-to by p
, atomically. Effectively executes p->swap(r)
and returns a copy of r
after the swap.
Equivalent to atomic_compare_exchange_weak_explicit(p, expected, desired, std::memory_order_seq_cst, std::memory_order_seq_cst)
Equivalent to atomic_compare_exchange_strong_explicit(p, expected, desired, std::memory_order_seq_cst, std::memory_order_seq_cst)
Compares the shared pointers pointed-to by p
and expected. 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
.
Same as 10), but may fail spuriously.
All these functions invoke undefined behavior if p
is a null pointer
.