template< class T >
struct atomic_ref;
The std::atomic_ref
class template applies atomic operations to the object it references.
For the lifetime of the std::atomic_ref
object, the object it references is considered an atomic object. 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.
The lifetime of an object must exceed the lifetime of all std::atomic_ref
s that references the object. While any std::atomic_ref
instance referencing an object exists, the object must be exclusively accessed through these std::atomic_ref
instances. No subobject of an object referenced by an std::atomic_ref
object may be concurrently referenced by any other std::atomic_ref
object.
Atomic operations applied to an object through an std::atomic_ref
are atomic with respect to atomic operations applied through any other std::atomic_ref
referencing the same object.
Like references in the core language, constness is shallow for std::atomic_ref
- it is possible to modify the referenced value through a const std::atomic_ref
object.
If any of the following conditions are satisfied, the program is ill-formed:
is_always_lock_free
is false and std::is_volatile_v<T> is true.std::atomic_ref
is CopyConstructible.
value_type
std::remove_cv_t<T> difference_type
value_type
, if T
is an arithmetic type other than cv bool.T
is a pointer-to-object type.ptr
the pointer to the referenced object
atomic_ref
atomic_ref
object
atomic_ref
object
atomic_ref
object is lock-free
T
is an arithmetic type other than cv bool or a pointer-to-object type atomically adds the argument to the value stored in the referenced object and obtains the value held previously
T
is an integral type other than cv bool or a pointer-to-object type atomically performs std::max between the argument and the value of the referenced object and obtains the value held previously
T
is an integral type other than cv bool atomically performs bitwise AND between the argument and the value of the referenced object and obtains the value held previously
The standard specifies that std::atomic_ref
has following specializations:
template<>
struct atomic_ref</*integral-type*/>;
template<>
struct atomic_ref</*floating-point-type*/>;
requires /* see below */
1) /*integral-type*/ denotes a possibly cv-qualified integral type other than cv bool.
2) /*floating-point-type*/ denotes a possibly cv-qualified floating-point type.
3) The partial specialization is provided for /*pointer-type*/ types that are possibly cv-qualified pointer-to-object types.
[edit] NotesImplementations may merge the specified specializations. E.g. MSVC STL merges all of them into the primary template.
When T
is cv void or a function type, std::atomic_ref<T*> (i.e. std::atomic_ref<void*>, std::atomic_ref<int(*)()> etc.) does not have difference_type
or any operation requiring pointer arithmetic or relational comparison(since C++26).
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3508T
is a const type or pointer-to-non-object type these operations are either constained
T
[edit] See also atomic class template and specializations for bool, integral, floating-point,(since C++20) and pointer types
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4