cpp/atomic/atomic

Each instantiation and full specialization of the 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 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.

is neither copyable nor movable.

Primary template
The primary template may be instantiated with any  type  satisfying both  and. The program is ill-formed if any of following values is :

uses the primary template. It is guaranteed to be a standard layout struct.

Partial specializations
The standard library provides partial specializations of the template for the following types with additional properties that the primary template does not have:

2) Partial specializations for all pointer types. These specializations have standard layout and trivial destructors. Besides the operations provided for all atomic types, these specializations additionally support atomic arithmetic operations appropriate to pointer types, such as,.

Specializations for integral types
When instantiated with one of the following integral types, provides additional atomic operations appropriate to integral types such as, , , , :
 * The character types, , , and ;
 * The standard signed integer types:, , , , and ;
 * The standard unsigned integer types:, , , , and ;
 * Any additional integral types needed by the typedefs in the header.

Additionally, the resulting specialization has standard layout and a trivial destructor. Signed integer arithmetic is defined to use two's complement; there are no undefined results.

{{rrev|since=c++20|

Specializations for floating-point types
When instantiated with one of the cv-unqualified floating-point types, provides additional atomic operations appropriate to floating-point types such as  and.

Additionally, the resulting specialization has standard layout and a trivial destructor.

No operations result in undefined behavior even if the result is not representable in the floating-point type. The floating-point environment in effect may be different from the calling thread's floating-point environment. }}

Type aliases
Type aliases are provided for and all integral types listed above, as follows:

Note:, , , and are defined if and only if , , std, and std are defined, respectively.

Member types
}

is not defined in the primary template or in the partial specializations for std and std.