Namespaces
Variants

std::atomic<T>::atomic

From cppreference.com
 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
Read-Copy-Update Mechanism
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
(C++11)(deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
 
 
constexpr atomic() noexcept(std::is_nothrow_default_constructible_v<T>);
(1) (since C++11)
constexpr atomic( T desired ) noexcept;
(2) (since C++11)
atomic( const atomic& ) = delete;
(3) (since C++11)

Constructs a new atomic variable.

1) Value-initializes the underlying object (i.e. with T()). The initialization is not atomic.
This overload participates in overload resolution only if std::is_default_constructible_v<T> is true.
2) Initializes the underlying object with desired. The initialization is not atomic.
3) Atomic variables are not CopyConstructible.

Parameters

desired - value to initialize with

Note

In libstdc++, libc++, LWG issue 2334 was only fixed in C++20 and later. Prior to the fix, the above implementations all initialize the underlying object by default-initialization.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 4169 C++11 std::is_default_constructible_v could report false positive the default constructor is constrained
LWG 2334 C++11 The default constructor does not create a T object Corrected

See also

(C++11)(deprecated in C++20)
non-atomic initialization of a default-constructed atomic object
(function template) [edit]