std::atomic (3) - Linux Man Pages
Defined in header <atomic>
template< class T > (1) (since C++11)
template< class T > (2) (since C++11)
Defined in header <memory>
template<class T> (3) (since C++20)
template<class T> (4) (since C++20)
Each instantiation and full specialization of the std::atomic template defines an atomic type. If one thread writes to an atomic object while another thread reads from it, the behavior is well-defined (see memory_model for details on data races)
In addition, accesses to atomic objects may establish inter-thread synchronization and order non-atomic memory accesses as specified by std::memory_order.
std::atomic is neither copyable nor movable.
The primary std::atomic template may be instantiated with any TriviallyCopyable type T satisfying both CopyConstructible and CopyAssignable. The program is ill-formed if any of following values is false:
std::atomic<bool> uses the primary template. It is guaranteed to be a standard layout struct.
The standard library provides partial specializations of the std::atomic template for the following types with additional properties that the primary template does not have:
2) Partial specializations std::atomic<T*> for all pointer types. These specializations have standard layout, trivial default constructors, and trivial destructors. Besides the operations provided for all atomic types, these specializations additionally support atomic arithmetic operations appropriate to pointer types, such as fetch_add, fetch_sub.
3-4) Partial specializations std::atomic<std::shared_ptr<T>> and std::atomic<std::weak_ptr<T>> are provided for std::shared_ptr and std::weak_ptr. (since C++20)
See std::atomic<std::shared_ptr> and std::atomic<std::weak_ptr> for details.
Specializations for integral types
When instantiated with one of the following integral types, std::atomic provides additional atomic operations appropriate to integral types such as fetch_add, fetch_sub, fetch_and, fetch_or, fetch_xor:
Additionally, the resulting std::atomic<Integral> specialization has standard layout, a trivial default constructor, and a trivial destructor. Signed integer arithmetic is defined to use two's complement; there are no undefined results.
Specializations for floating-point types