std::atomic_...<std::shared_ptr>

Header: <memory>

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.).

# Declarations

template< class T >
bool atomic_is_lock_free( const std::shared_ptr<T>* p );

(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 );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
std::shared_ptr<T> atomic_load_explicit
( const std::shared_ptr<T>* p, std::memory_order mo );

(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 );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
void atomic_store_explicit
( std::shared_ptr<T>* p, std::shared_ptr<T> r,
std::memory_order mo );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
std::shared_ptr<T> atomic_exchange
( std::shared_ptr<T>* p, std::shared_ptr<T> r );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
std::shared_ptr<T> atomic_exchange_explicit
( std::shared_ptr<T>* p, std::shared_ptr<T> r,
std::memory_order mo );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
bool atomic_compare_exchange_weak
( std::shared_ptr<T>* p, std::shared_ptr<T>* expected,
std::shared_ptr<T> desired );

(since C++11) (deprecated in C++20) (removed in C++26)

template< class T >
bool atomic_compare_exchange_strong
( std::shared_ptr<T>* p, std::shared_ptr<T>* expected,
std::shared_ptr<T> desired );

(since C++11) (deprecated in C++20) (removed in C++26)

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 );

(since C++11) (deprecated in C++20) (removed in C++26)

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 );

(since C++11) (deprecated in C++20) (removed in C++26)

# Parameters

# Notes

These functions are typically implemented using mutexes, stored in a global hash table where the pointer value is used as the key.

The Concurrency TS offers atomic smart pointer classes atomic_shared_ptr and atomic_weak_ptr as a replacement for the use of these functions.

These functions were deprecated in favor of the specializations of the std::atomic template: std::atomic<std::shared_ptr> and std::atomic<std::weak_ptr>.

These functions were removed in favor of the specializations of the std::atomic template: std::atomic<std::shared_ptr> and std::atomic<std::weak_ptr>.

# Example

This section is incompleteReason: no example

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2172C++11expected could be a null pointerthe behavior is undefined in this case
LWG 2980C++11empty shared_ptrs were never equivalentequivalent if they store the same pointer value

# See also