[atomics.types.generic]

# 32 Concurrency support library [[thread]](./#thread)

## 32.5 Atomic operations [[atomics]](atomics#types.generic)

### 32.5.8 Class template atomic [atomics.types.generic]

#### [32.5.8.1](#general) General [[atomics.types.generic.general]](atomics.types.generic.general)

[ð](#lib:atomic)

namespace std {template<class T> struct atomic {using value_type = T; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const volatile noexcept; bool is_lock_free() const noexcept; // [[atomics.types.operations]](#atomics.types.operations "32.5.8.2 Operations on atomic types"), operations on atomic typesconstexpr atomic() noexcept(is_nothrow_default_constructible_v<T>); constexpr atomic(T) noexcept;
 atomic(const atomic&) = delete;
 atomic& operator=(const atomic&) = delete;
 atomic& operator=(const atomic&) volatile = delete;

 T load(memory_order = memory_order::seq_cst) const volatile noexcept; constexpr T load(memory_order = memory_order::seq_cst) const noexcept; operator T() const volatile noexcept; constexpr operator T() const noexcept; void store(T, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store(T, memory_order = memory_order::seq_cst) noexcept;
 T operator=(T) volatile noexcept; constexpr T operator=(T) noexcept;

 T exchange(T, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T exchange(T, memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_weak(T&, T, memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_weak(T&, T, memory_order, memory_order) noexcept; bool compare_exchange_strong(T&, T, memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_strong(T&, T, memory_order, memory_order) noexcept; bool compare_exchange_weak(T&, T, memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_weak(T&, T, memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_strong(T&, T, memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_strong(T&, T, memory_order = memory_order::seq_cst) noexcept; void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept; constexpr void wait(T, memory_order = memory_order::seq_cst) const noexcept; void notify_one() volatile noexcept; constexpr void notify_one() noexcept; void notify_all() volatile noexcept; constexpr void notify_all() noexcept; };}

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4498)

The template argument for T shall meet the[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#general-1.sentence-1)

The program is ill-formed if any of

- [(1.1)](#general-1.1)

is_trivially_copyable_v<T>,

- [(1.2)](#general-1.2)

is_copy_constructible_v<T>,

- [(1.3)](#general-1.3)

is_move_constructible_v<T>,

- [(1.4)](#general-1.4)

is_copy_assignable_v<T>,

- [(1.5)](#general-1.5)

is_move_assignable_v<T>, or

- [(1.6)](#general-1.6)

same_as<T, remove_cv_t<T>>,

is false[.](#general-1.sentence-2)

[*Note [1](#general-note-1)*:

Type arguments that are
not also statically initializable can be difficult to use[.](#general-1.sentence-3)

â *end note*]

[2](#general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4516)

The specialization atomic<bool> is a standard-layout struct[.](#general-2.sentence-1)

It has a trivial destructor[.](#general-2.sentence-2)

[3](#general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4520)

[*Note [2](#general-note-2)*:

The representation of an atomic specialization
need not have the same size and alignment requirement as
its corresponding argument type[.](#general-3.sentence-1)

â *end note*]

#### [32.5.8.2](#atomics.types.operations) Operations on atomic types [[atomics.types.operations]](atomics.types.operations)

[ð](#lib:atomic,constructor)

`constexpr atomic() noexcept(is_nothrow_default_constructible_v<T>);
`

[1](#atomics.types.operations-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4538)

*Constraints*: is_default_constructible_v<T> is true[.](#atomics.types.operations-1.sentence-1)

[2](#atomics.types.operations-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4542)

*Effects*: Initializes the atomic object with the value of T()[.](#atomics.types.operations-2.sentence-1)

Initialization is not an atomic operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.operations-2.sentence-2)

[ð](#lib:atomic,constructor_)

`constexpr atomic(T desired) noexcept;
`

[3](#atomics.types.operations-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4557)

*Effects*: Initializes the object with the value desired[.](#atomics.types.operations-3.sentence-1)

Initialization is not an atomic operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.operations-3.sentence-2)

[*Note [1](#atomics.types.operations-note-1)*:

It is possible to have an access to an atomic object A race with its construction, for example by communicating the address of the
just-constructed object A to another thread viamemory_order​::​relaxed operations on a suitable atomic pointer
variable, and then immediately accessing A in the receiving thread[.](#atomics.types.operations-3.sentence-3)

This results in undefined behavior[.](#atomics.types.operations-3.sentence-4)

â *end note*]

[ð](#lib:is_always_lock_free,atomic)

`static constexpr bool is_always_lock_free = implementation-defined;
`

[4](#atomics.types.operations-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4582)

The static data member is_always_lock_free is true if the atomic type's operations are always lock-free, and false otherwise[.](#atomics.types.operations-4.sentence-1)

[*Note [2](#atomics.types.operations-note-2)*:

The value of is_always_lock_free is consistent with the value of
the corresponding ATOMIC_..._LOCK_FREE macro, if defined[.](#atomics.types.operations-4.sentence-2)

â *end note*]

[ð](#lib:atomic_is_lock_free)

`bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
`

[5](#atomics.types.operations-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4604)

*Returns*: true if the object's operations are lock-free, false otherwise[.](#atomics.types.operations-5.sentence-1)

[*Note [3](#atomics.types.operations-note-3)*:

The return value of the is_lock_free member function
is consistent with the value of is_always_lock_free for the same type[.](#atomics.types.operations-5.sentence-2)

â *end note*]

[ð](#lib:atomic_store)

`void store(T desired, memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr void store(T desired, memory_order order = memory_order::seq_cst) noexcept;
`

[6](#atomics.types.operations-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4625)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-6.sentence-1)

[7](#atomics.types.operations-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4630)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​release, ormemory_order​::​seq_cst[.](#atomics.types.operations-7.sentence-1)

[8](#atomics.types.operations-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4637)

*Effects*: Atomically replaces the value pointed to by this with the value of desired[.](#atomics.types.operations-8.sentence-1)

Memory is affected according to the value oforder[.](#atomics.types.operations-8.sentence-2)

[ð](#lib:operator=,atomic)

`T operator=(T desired) volatile noexcept;
constexpr T operator=(T desired) noexcept;
`

[9](#atomics.types.operations-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4654)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-9.sentence-1)

[10](#atomics.types.operations-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4659)

*Effects*: Equivalent to store(desired)[.](#atomics.types.operations-10.sentence-1)

[11](#atomics.types.operations-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4663)

*Returns*: desired[.](#atomics.types.operations-11.sentence-1)

[ð](#lib:atomic_load)

`T load(memory_order order = memory_order::seq_cst) const volatile noexcept;
constexpr T load(memory_order order = memory_order::seq_cst) const noexcept;
`

[12](#atomics.types.operations-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4680)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-12.sentence-1)

[13](#atomics.types.operations-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4685)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#atomics.types.operations-13.sentence-1)

[14](#atomics.types.operations-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4692)

*Effects*: Memory is affected according to the value of order[.](#atomics.types.operations-14.sentence-1)

[15](#atomics.types.operations-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4696)

*Returns*: Atomically returns the value pointed to by this[.](#atomics.types.operations-15.sentence-1)

[ð](#lib:operator_type,atomic)

`operator T() const volatile noexcept;
constexpr operator T() const noexcept;
`

[16](#atomics.types.operations-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4711)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-16.sentence-1)

[17](#atomics.types.operations-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4716)

*Effects*: Equivalent to: return load();

[ð](#lib:atomic_exchange)

`T exchange(T desired, memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr T exchange(T desired, memory_order order = memory_order::seq_cst) noexcept;
`

[18](#atomics.types.operations-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4734)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-18.sentence-1)

[19](#atomics.types.operations-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4739)

*Effects*: Atomically replaces the value pointed to by this with desired[.](#atomics.types.operations-19.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.operations-19.sentence-2)

These operations are atomic read-modify-write operations ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.operations-19.sentence-3)

[20](#atomics.types.operations-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4746)

*Returns*: Atomically returns the value pointed to by this immediately before the effects[.](#atomics.types.operations-20.sentence-1)

[ð](#lib:atomic_compare_exchange_weak)

`bool compare_exchange_weak(T& expected, T desired,
                           memory_order success, memory_order failure) volatile noexcept;
constexpr bool compare_exchange_weak(T& expected, T desired,
                           memory_order success, memory_order failure) noexcept;
bool compare_exchange_strong(T& expected, T desired,
                             memory_order success, memory_order failure) volatile noexcept;
constexpr bool compare_exchange_strong(T& expected, T desired,
                             memory_order success, memory_order failure) noexcept;
bool compare_exchange_weak(T& expected, T desired,
                           memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr bool compare_exchange_weak(T& expected, T desired,
                           memory_order order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(T& expected, T desired,
                             memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr bool compare_exchange_strong(T& expected, T desired,
                             memory_order order = memory_order::seq_cst) noexcept;
`

[21](#atomics.types.operations-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4783)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.operations-21.sentence-1)

[22](#atomics.types.operations-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4788)

*Preconditions*: failure ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#atomics.types.operations-22.sentence-1)

[23](#atomics.types.operations-23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4795)

*Effects*: Retrieves the value in expected[.](#atomics.types.operations-23.sentence-1)

It then atomically
compares the value representation of the value pointed to by this for equality with that previously retrieved from expected,
and if true, replaces the value pointed to
by this with that in desired[.](#atomics.types.operations-23.sentence-2)

If and only if the comparison is true, memory is affected according to the
value of success, and if the comparison is false, memory is affected according
to the value of failure[.](#atomics.types.operations-23.sentence-3)

When only one memory_order argument is
supplied, the value of success is order, and the value offailure is order except that a value of memory_order​::​acq_rel shall be replaced by the value memory_order​::​acquire and a value ofmemory_order​::​release shall be replaced by the valuememory_order​::​relaxed[.](#atomics.types.operations-23.sentence-4)

If and only if the comparison is false then, after the atomic operation,
the value in expected is replaced by the value
pointed to by this during the atomic comparison[.](#atomics.types.operations-23.sentence-5)

If the operation returns true, these
operations are atomic read-modify-write
operations ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) on the memory
pointed to by this[.](#atomics.types.operations-23.sentence-6)

Otherwise, these operations are atomic load operations on that memory[.](#atomics.types.operations-23.sentence-7)

[24](#atomics.types.operations-24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4819)

*Returns*: The result of the comparison[.](#atomics.types.operations-24.sentence-1)

[25](#atomics.types.operations-25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4823)

[*Note [4](#atomics.types.operations-note-4)*:

For example, the effect ofcompare_exchange_strong on objects without padding bits ([[basic.types.general]](basic.types.general#term.padding.bits "6.9.1 General")) isif (memcmp(this, &expected, sizeof(*this)) == 0) memcpy(this, &desired, sizeof(*this));else memcpy(&expected, this, sizeof(*this));

â *end note*]

[*Example [1](#atomics.types.operations-example-1)*:

The expected use of the compare-and-exchange operations is as follows[.](#atomics.types.operations-25.sentence-2)

The
compare-and-exchange operations will update expected when another iteration of
the loop is needed[.](#atomics.types.operations-25.sentence-3)

expected = current.load();do { desired = function(expected);} while (!current.compare_exchange_weak(expected, desired)); â *end example*]

[*Example [2](#atomics.types.operations-example-2)*:

Because the expected value is updated only on failure,
code releasing the memory containing the expected value on success will work[.](#atomics.types.operations-25.sentence-4)

For example, list head insertion will act atomically and would not introduce a
data race in the following code:do { p->next = head; // make new list node point to the current head} while (!head.compare_exchange_weak(p->next, p)); // try to insert

â *end example*]

[26](#atomics.types.operations-26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4858)

Implementations should ensure that weak compare-and-exchange operations do not
consistently return false unless either the atomic object has value
different from expected or there are concurrent modifications to the
atomic object[.](#atomics.types.operations-26.sentence-1)

[27](#atomics.types.operations-27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4864)

*Remarks*: A weak compare-and-exchange operation may fail spuriously[.](#atomics.types.operations-27.sentence-1)

That is, even when
the contents of memory referred to by expected and this are
equal, it may return false and store back to expected the same memory
contents that were originally there[.](#atomics.types.operations-27.sentence-2)

[*Note [5](#atomics.types.operations-note-5)*:

This
spurious failure enables implementation of compare-and-exchange on a broader class of
machines, e.g., load-locked store-conditional machines[.](#atomics.types.operations-27.sentence-3)

A
consequence of spurious failure is that nearly all uses of weak compare-and-exchange
will be in a loop[.](#atomics.types.operations-27.sentence-4)

When a compare-and-exchange is in a loop, the weak version will yield better performance
on some platforms[.](#atomics.types.operations-27.sentence-5)

When a weak compare-and-exchange would require a loop and a strong one
would not, the strong one is preferable[.](#atomics.types.operations-27.sentence-6)

â *end note*]

[28](#atomics.types.operations-28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4881)

[*Note [6](#atomics.types.operations-note-6)*:

Under cases where the memcpy and memcmp semantics of the compare-and-exchange
operations apply, the comparisons can fail for values that compare equal withoperator== if the value representation has trap bits or alternate
representations of the same value[.](#atomics.types.operations-28.sentence-1)

Notably, on implementations conforming to
ISO/IEC 60559, floating-point -0.0 and +0.0 will not compare equal with memcmp but will compare equal with operator==,
and NaNs with the same payload will compare equal with memcmp but will not
compare equal with operator==[.](#atomics.types.operations-28.sentence-2)

â *end note*]

[*Note [7](#atomics.types.operations-note-7)*:

Because compare-and-exchange acts on an object's value representation,
padding bits that never participate in the object's value representation
are ignored[.](#atomics.types.operations-28.sentence-3)

As a consequence, the following code is guaranteed to avoid
spurious failure:struct padded {char clank = 0x42; // Padding here.unsigned biff = 0xC0DEFEFE;};
atomic<padded> pad = {};

bool zap() { padded expected, desired{0, 0}; return pad.compare_exchange_strong(expected, desired);}

â *end note*]

[*Note [8](#atomics.types.operations-note-8)*:

For a union with bits that participate in the value representation
of some members but not others, compare-and-exchange might always fail[.](#atomics.types.operations-28.sentence-5)

This is because such padding bits have an indeterminate value when they
do not participate in the value representation of the active member[.](#atomics.types.operations-28.sentence-6)

As a consequence, the following code is not guaranteed to ever succeed:union pony {double celestia = 0.; short luna; // padded};
atomic<pony> princesses = {};

bool party(pony desired) { pony expected; return princesses.compare_exchange_strong(expected, desired);}

â *end note*]

[ð](#lib:wait,atomic)

`void wait(T old, memory_order order = memory_order::seq_cst) const volatile noexcept;
constexpr void wait(T old, memory_order order = memory_order::seq_cst) const noexcept;
`

[29](#atomics.types.operations-29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4942)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#atomics.types.operations-29.sentence-1)

[30](#atomics.types.operations-30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4949)

*Effects*: Repeatedly performs the following steps, in order:

- [(30.1)](#atomics.types.operations-30.1)

  Evaluates load(order) and
 compares its value representation for equality against that of old[.](#atomics.types.operations-30.1.sentence-1)

- [(30.2)](#atomics.types.operations-30.2)

  If they compare unequal, returns[.](#atomics.types.operations-30.2.sentence-1)

- [(30.3)](#atomics.types.operations-30.3)

  Blocks until it
 is unblocked by an atomic notifying operation or is unblocked spuriously[.](#atomics.types.operations-30.3.sentence-1)

[31](#atomics.types.operations-31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4963)

*Remarks*: This function is an atomic waiting operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#atomics.types.operations-31.sentence-1)

[ð](#lib:notify_one,atomic)

`void notify_one() volatile noexcept;
constexpr void notify_one() noexcept;
`

[32](#atomics.types.operations-32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4978)

*Effects*: Unblocks the execution of at least one atomic waiting operation
that is eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call,
if any such atomic waiting operations exist[.](#atomics.types.operations-32.sentence-1)

[33](#atomics.types.operations-33)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4984)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#atomics.types.operations-33.sentence-1)

[ð](#lib:notify_all,atomic)

`void notify_all() volatile noexcept;
constexpr void notify_all() noexcept;
`

[34](#atomics.types.operations-34)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L4999)

*Effects*: Unblocks the execution of all atomic waiting operations
that are eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call[.](#atomics.types.operations-34.sentence-1)

[35](#atomics.types.operations-35)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5004)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#atomics.types.operations-35.sentence-1)

#### [32.5.8.3](#atomics.types.int) Specializations for integers [[atomics.types.int]](atomics.types.int)

[1](#atomics.types.int-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5012)

There are specializations of the atomic class template for the integral typeschar,signed char,unsigned char,short,unsigned short,int,unsigned int,long,unsigned long,long long,unsigned long long,char8_t,char16_t,char32_t,wchar_t,
and any other types needed by the typedefs in the header [<cstdint>](cstdint.syn#header:%3ccstdint%3e "17.4.1 Header <cstdint> synopsis [cstdint.syn]")[.](#atomics.types.int-1.sentence-1)

For each such type *integral-type*, the specializationatomic<*integral-type*> provides additional atomic operations appropriate to integral types[.](#atomics.types.int-1.sentence-2)

[*Note [1](#atomics.types.int-note-1)*:

The specialization atomic<bool> uses the primary template ([atomics.types.generic])[.](#atomics.types.int-1.sentence-3)

â *end note*]

namespace std {template<> struct atomic<*integral-type*> {using value_type = *integral-type*; using difference_type = value_type; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const volatile noexcept; bool is_lock_free() const noexcept; constexpr atomic() noexcept; constexpr atomic(*integral-type*) noexcept;
 atomic(const atomic&) = delete;
 atomic& operator=(const atomic&) = delete;
 atomic& operator=(const atomic&) volatile = delete; void store(*integral-type*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store(*integral-type*, memory_order = memory_order::seq_cst) noexcept; *integral-type* operator=(*integral-type*) volatile noexcept; constexpr *integral-type* operator=(*integral-type*) noexcept; *integral-type* load(memory_order = memory_order::seq_cst) const volatile noexcept; constexpr *integral-type* load(memory_order = memory_order::seq_cst) const noexcept; operator *integral-type*() const volatile noexcept; constexpr operator *integral-type*() const noexcept; *integral-type* exchange(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* exchange(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_weak(*integral-type*&, *integral-type*,
 memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_weak(*integral-type*&, *integral-type*,
 memory_order, memory_order) noexcept; bool compare_exchange_strong(*integral-type*&, *integral-type*,
 memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_strong(*integral-type*&, *integral-type*,
 memory_order, memory_order) noexcept; bool compare_exchange_weak(*integral-type*&, *integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_weak(*integral-type*&, *integral-type*,
 memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_strong(*integral-type*&, *integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_strong(*integral-type*&, *integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_add(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_add(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_sub(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_sub(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_and(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_and(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_or(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_or(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_xor(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_xor(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_max(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_max(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* fetch_min(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *integral-type* fetch_min(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_add(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_add(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_sub(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_sub(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_and(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_and(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_or(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_or(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_xor(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_xor(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_max(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_max(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_min(*integral-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_min(*integral-type*,
 memory_order = memory_order::seq_cst) noexcept; *integral-type* operator++(int) volatile noexcept; constexpr *integral-type* operator++(int) noexcept; *integral-type* operator--(int) volatile noexcept; constexpr *integral-type* operator--(int) noexcept; *integral-type* operator++() volatile noexcept; constexpr *integral-type* operator++() noexcept; *integral-type* operator--() volatile noexcept; constexpr *integral-type* operator--() noexcept; *integral-type* operator+=(*integral-type*) volatile noexcept; constexpr *integral-type* operator+=(*integral-type*) noexcept; *integral-type* operator-=(*integral-type*) volatile noexcept; constexpr *integral-type* operator-=(*integral-type*) noexcept; *integral-type* operator&=(*integral-type*) volatile noexcept; constexpr *integral-type* operator&=(*integral-type*) noexcept; *integral-type* operator|=(*integral-type*) volatile noexcept; constexpr *integral-type* operator|=(*integral-type*) noexcept; *integral-type* operator^=(*integral-type*) volatile noexcept; constexpr *integral-type* operator^=(*integral-type*) noexcept; void wait(*integral-type*, memory_order = memory_order::seq_cst) const volatile noexcept; constexpr void wait(*integral-type*, memory_order = memory_order::seq_cst) const noexcept; void notify_one() volatile noexcept; constexpr void notify_one() noexcept; void notify_all() volatile noexcept; constexpr void notify_all() noexcept; };}

[2](#atomics.types.int-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5171)

The atomic integral specializations
are standard-layout structs[.](#atomics.types.int-2.sentence-1)

They each have
a trivial destructor[.](#atomics.types.int-2.sentence-2)

[3](#atomics.types.int-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5177)

Descriptions are provided below only for members that differ from the primary template[.](#atomics.types.int-3.sentence-1)

[4](#atomics.types.int-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5180)

The following operations perform arithmetic computations[.](#atomics.types.int-4.sentence-1)

The correspondence among key, operator, and computation is specified
in Table [155](#tab:atomic.types.int.comp "Table 155: Atomic arithmetic computations")[.](#atomics.types.int-4.sentence-2)

Table [155](#tab:atomic.types.int.comp) — Atomic arithmetic computations [[tab:atomic.types.int.comp]](./tab:atomic.types.int.comp)  

| [ð](#tab:atomic.types.int.comp-row-1)<br>***key*** | **Op** | **Computation** | ***key*** | **Op** | **Computation** |
| --- | --- | --- | --- | --- | --- |
| [ð](#tab:atomic.types.int.comp-row-2)<br>add | + | addition | and | & | bitwise and |
| [ð](#tab:atomic.types.int.comp-row-3)<br>sub | - | subtraction | or | | | bitwise inclusive or |
| [ð](#tab:atomic.types.int.comp-row-4)<br>max |  | maximum | xor | ^ | bitwise exclusive or |
| [ð](#tab:atomic.types.int.comp-row-5)<br>min |  | minimum |  |  |  |

[ð](#lib:atomic_fetch_add)

`integral-type fetch_key(integral-type operand,
                         memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr integral-type fetch_key(integral-type operand,
                                   memory_order order = memory_order::seq_cst) noexcept;
`

[5](#atomics.types.int-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5246)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.int-5.sentence-1)

[6](#atomics.types.int-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5251)

*Effects*: Atomically replaces the value pointed to bythis with the result of the computation applied to the
value pointed to by this and the given operand[.](#atomics.types.int-6.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.int-6.sentence-2)

These operations are atomic read-modify-write operations ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.int-6.sentence-3)

[7](#atomics.types.int-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5259)

*Returns*: Atomically, the value pointed to by this immediately before the effects[.](#atomics.types.int-7.sentence-1)

[8](#atomics.types.int-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5263)

*Remarks*: Except for fetch_max and fetch_min, for signed integer types
the result is as if the object value and parameters
were converted to their corresponding unsigned types,
the computation performed on those types, and
the result converted back to the signed type[.](#atomics.types.int-8.sentence-1)

[*Note [2](#atomics.types.int-note-2)*:

There are no undefined results arising from the computation[.](#atomics.types.int-8.sentence-2)

â *end note*]

[9](#atomics.types.int-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5275)

For fetch_max and fetch_min, the maximum and minimum
computation is performed as if by max and min algorithms ([[alg.min.max]](alg.min.max "26.8.9 Minimum and maximum")), respectively,
with the object value and the first parameter as the arguments[.](#atomics.types.int-9.sentence-1)

[ð](#lib:atomic_store_add)

`void store_key(integral-type operand,
                memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr void store_key(integral-type operand,
                          memory_order order = memory_order::seq_cst) noexcept;
`

[10](#atomics.types.int-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5308)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.int-10.sentence-1)

[11](#atomics.types.int-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5313)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​release, ormemory_order​::​seq_cst[.](#atomics.types.int-11.sentence-1)

[12](#atomics.types.int-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5320)

*Effects*: Atomically replaces the value pointed to by this with the result of the computation applied to
the value pointed to by this and the given operand[.](#atomics.types.int-12.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.int-12.sentence-2)

These operations are atomic modify-write operations ([[atomics.order]](atomics.order "32.5.4 Order and consistency"))[.](#atomics.types.int-12.sentence-3)

[13](#atomics.types.int-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5328)

*Remarks*: Except for store_max and store_min,
for signed integer types, the result is as if
the value pointed to by this and parameters
were converted to their corresponding unsigned types,
the computation performed on those types, and
the result converted back to the signed type[.](#atomics.types.int-13.sentence-1)

[*Note [3](#atomics.types.int-note-3)*:

There are no undefined results arising from the computation[.](#atomics.types.int-13.sentence-2)

â *end note*]

For store_max and store_min,
the maximum and minimum computation is performed
as if by max and min algorithms ([[alg.min.max]](alg.min.max "26.8.9 Minimum and maximum")), respectively,
with the value pointed to by this and the first parameter as the arguments[.](#atomics.types.int-13.sentence-3)

[ð](#lib:operator+=,atomic%3cT*%3e)

`integral-type operator op=(integral-type operand) volatile noexcept;
constexpr integral-type operator op=(integral-type operand) noexcept;
`

[14](#atomics.types.int-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5358)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.int-14.sentence-1)

[15](#atomics.types.int-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5363)

*Effects*: Equivalent to: return fetch_*key*(operand) *op* operand;

#### [32.5.8.4](#atomics.types.float) Specializations for floating-point types [[atomics.types.float]](atomics.types.float)

[1](#atomics.types.float-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5371)

There are specializations of the atomic class template for all cv-unqualified floating-point types[.](#atomics.types.float-1.sentence-1)

For each such type *floating-point-type*,
the specialization atomic<*floating-point-type*> provides additional atomic operations appropriate to floating-point types[.](#atomics.types.float-1.sentence-2)

namespace std {template<> struct atomic<*floating-point-type*> {using value_type = *floating-point-type*; using difference_type = value_type; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const volatile noexcept; bool is_lock_free() const noexcept; constexpr atomic() noexcept; constexpr atomic(*floating-point-type*) noexcept;
 atomic(const atomic&) = delete;
 atomic& operator=(const atomic&) = delete;
 atomic& operator=(const atomic&) volatile = delete; void store(*floating-point-type*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store(*floating-point-type*, memory_order = memory_order::seq_cst) noexcept; *floating-point-type* operator=(*floating-point-type*) volatile noexcept; constexpr *floating-point-type* operator=(*floating-point-type*) noexcept; *floating-point-type* load(memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* load(memory_order = memory_order::seq_cst) noexcept; operator *floating-point-type*() volatile noexcept; constexpr operator *floating-point-type*() noexcept; *floating-point-type* exchange(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* exchange(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
 memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
 memory_order, memory_order) noexcept; bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
 memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
 memory_order, memory_order) noexcept; bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_add(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_add(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_sub(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_sub(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_max(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_max(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_min(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-poin-type*t fetch_min(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_fmaximum(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_fmaximum(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_fminimum(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_fminimum(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_fmaximum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_fmaximum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* fetch_fminimum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr *floating-point-type* fetch_fminimum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_add(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_add(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_sub(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_sub(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_max(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_max(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_min(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_min(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_fmaximum(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_fmaximum(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_fminimum(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_fminimum(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_fmaximum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_fmaximum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; void store_fminimum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_fminimum_num(*floating-point-type*,
 memory_order = memory_order::seq_cst) noexcept; *floating-point-type* operator+=(*floating-point-type*) volatile noexcept; constexpr *floating-point-type* operator+=(*floating-point-type*) noexcept; *floating-point-type* operator-=(*floating-point-type*) volatile noexcept; constexpr *floating-point-type* operator-=(*floating-point-type*) noexcept; void wait(*floating-point-type*, memory_order = memory_order::seq_cst) const volatile noexcept; constexpr void wait(*floating-point-type*,
 memory_order = memory_order::seq_cst) const noexcept; void notify_one() volatile noexcept; constexpr void notify_one() noexcept; void notify_all() volatile noexcept; constexpr void notify_all() noexcept; };}

[2](#atomics.types.float-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5506)

The atomic floating-point specializations
are standard-layout structs[.](#atomics.types.float-2.sentence-1)

They each have
a trivial destructor[.](#atomics.types.float-2.sentence-2)

[3](#atomics.types.float-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5512)

Descriptions are provided below only for members that differ from the primary template[.](#atomics.types.float-3.sentence-1)

[4](#atomics.types.float-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5515)

The following operations perform arithmetic addition and subtraction computations[.](#atomics.types.float-4.sentence-1)

The correspondence among key, operator, and computation is specified
in Table [155](#tab:atomic.types.int.comp "Table 155: Atomic arithmetic computations"),
except for the keysmax,min,fmaximum,fminimum,fmaximum_num, andfminimum_num,
which are specified below[.](#atomics.types.float-4.sentence-2)

[ð](#lib:atomic_fetch_add_)

`floating-point-type fetch_key(floating-point-type operand,
                               memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr floating-point-type fetch_key(floating-point-type operand,
                                         memory_order order = memory_order::seq_cst) noexcept;
`

[5](#atomics.types.float-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5548)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.float-5.sentence-1)

[6](#atomics.types.float-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5553)

*Effects*: Atomically replaces the value pointed to by this with the result of the computation applied to the value pointed
to by this and the given operand[.](#atomics.types.float-6.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.float-6.sentence-2)

These operations are atomic read-modify-write operations ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.float-6.sentence-3)

[7](#atomics.types.float-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5561)

*Returns*: Atomically, the value pointed to by this immediately before the effects[.](#atomics.types.float-7.sentence-1)

[8](#atomics.types.float-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5565)

*Remarks*: If the result is not a representable value for its type ([[expr.pre]](expr.pre "7.1 Preamble"))
the result is unspecified, but the operations otherwise have no undefined
behavior[.](#atomics.types.float-8.sentence-1)

Atomic arithmetic operations on *floating-point-type* should conform to the std​::​numeric_limits<*floating-point-type*> traits associated with the floating-point type ([[limits.syn]](limits.syn "17.3.3 Header <limits> synopsis"))[.](#atomics.types.float-8.sentence-2)

The floating-point environment ([[cfenv]](cfenv "29.3 The floating-point environment")) for atomic arithmetic operations
on *floating-point-type* may be different than the
calling thread's floating-point environment[.](#atomics.types.float-8.sentence-3)

[9](#atomics.types.float-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5576)

- [(9.1)](#atomics.types.float-9.1)

  For fetch_fmaximum and fetch_fminimum,
the maximum and minimum computation is performed
as if by fmaximum and fminimum, respectively,
with the value pointed to by this and the first parameter
as the arguments[.](#atomics.types.float-9.1.sentence-1)

- [(9.2)](#atomics.types.float-9.2)

  For fetch_fmaximum_num and fetch_fminimum_num,
the maximum and minimum computation is performed
as if by fmaximum_num and fminimum_num, respectively,
with the value pointed to by this and the first parameter
as the arguments[.](#atomics.types.float-9.2.sentence-1)

- [(9.3)](#atomics.types.float-9.3)

  For fetch_max and fetch_min,
the maximum and minimum computation is performed
as if by fmaximum_num and fminimum_num, respectively,
with the value pointed to by this and the first parameter
as the arguments, except that:
  * [(9.3.1)](#atomics.types.float-9.3.1)

      If both arguments are NaN,
an unspecified NaN value replaces the value pointed to by this[.](#atomics.types.float-9.3.1.sentence-1)

  * [(9.3.2)](#atomics.types.float-9.3.2)

      If exactly one argument is a NaN,
either the other argument or an unspecified NaN value
replaces the value pointed to by this; it is unspecified which[.](#atomics.types.float-9.3.2.sentence-1)

  * [(9.3.3)](#atomics.types.float-9.3.3)

      If the arguments are differently signed zeros,
which of these values replaces the value pointed to by this is unspecified[.](#atomics.types.float-9.3.3.sentence-1)

[10](#atomics.types.float-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5610)

*Recommended practice*: The implementation of fetch_max and fetch_min should treat negative zero as smaller than positive zero[.](#atomics.types.float-10.sentence-1)

[ð](#lib:store_max,atomic%3cfloating-point-type%3e)

`void store_key(floating-point-type operand,
  memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr void store_key(floating-point-type operand,
  memory_order order = memory_order::seq_cst) noexcept;
`

[11](#atomics.types.float-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5630)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.float-11.sentence-1)

[12](#atomics.types.float-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5635)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​release, ormemory_order​::​seq_cst[.](#atomics.types.float-12.sentence-1)

[13](#atomics.types.float-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5642)

*Effects*: Atomically replaces the value pointed to by this with the result of the computation applied to
the value pointed to by this and the given operand[.](#atomics.types.float-13.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.float-13.sentence-2)

These operations are atomic modify-write operations ([[atomics.order]](atomics.order "32.5.4 Order and consistency"))[.](#atomics.types.float-13.sentence-3)

[14](#atomics.types.float-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5650)

*Remarks*: If the result is not a representable value for its type ([[expr.pre]](expr.pre "7.1 Preamble"))
the result is unspecified,
but the operations otherwise have no undefined behavior[.](#atomics.types.float-14.sentence-1)

Atomic arithmetic operations on *floating-point-type* should conform to the numeric_limits<*floating-point-type*> traits associated with the floating-point type ([[limits.syn]](limits.syn "17.3.3 Header <limits> synopsis"))[.](#atomics.types.float-14.sentence-2)

The floating-point environment ([[cfenv]](cfenv "29.3 The floating-point environment")) for
atomic arithmetic operations on *floating-point-type* may be different than the calling thread's floating-point environment[.](#atomics.types.float-14.sentence-3)

The arithmetic rules of floating-point atomic modify-write operations
may be different from operations on
floating-point types or atomic floating-point types[.](#atomics.types.float-14.sentence-4)

[*Note [1](#atomics.types.float-note-1)*:

Tree reductions are permitted for atomic modify-write operations[.](#atomics.types.float-14.sentence-5)

â *end note*]

[15](#atomics.types.float-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5668)

- [(15.1)](#atomics.types.float-15.1)

  For store_fmaximum and store_fminimum,
the maximum and minimum computation is performed
as if by fmaximum and fminimum, respectively,
with the value pointed to by this and
the first parameter as the arguments[.](#atomics.types.float-15.1.sentence-1)

- [(15.2)](#atomics.types.float-15.2)

  For store_fmaximum_num and store_fminimum_num,
the maximum and minimum computation is performed
as if by fmaximum_num and fminimum_num, respectively,
with the value pointed to by this and
the first parameter as the arguments[.](#atomics.types.float-15.2.sentence-1)

- [(15.3)](#atomics.types.float-15.3)

  For store_max and store_min,
the maximum and minimum computation is performed
as if by fmaximum_num and fminimum_num, respectively,
with the value pointed to by this and
the first parameter as the arguments, except that:
  * [(15.3.1)](#atomics.types.float-15.3.1)

      If both arguments are NaN,
an unspecified NaN value replaces the value pointed to by this[.](#atomics.types.float-15.3.1.sentence-1)

  * [(15.3.2)](#atomics.types.float-15.3.2)

      If exactly one argument is a NaN,
either the other argument or an unspecified NaN value replaces
the value pointed to by this;
it is unspecified which[.](#atomics.types.float-15.3.2.sentence-1)

  * [(15.3.3)](#atomics.types.float-15.3.3)

      If the arguments are differently signed zeros,
which of these values replaces the value pointed to by this is unspecified[.](#atomics.types.float-15.3.3.sentence-1)

[16](#atomics.types.float-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5703)

*Recommended practice*: The implementation of store_max and store_min should treat negative zero as smaller than positive zero[.](#atomics.types.float-16.sentence-1)

[ð](#lib:operator+=,atomic%3cT*%3e_)

`floating-point-type operator op=(floating-point-type operand) volatile noexcept;
constexpr floating-point-type operator op=(floating-point-type operand) noexcept;
`

[17](#atomics.types.float-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5719)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.float-17.sentence-1)

[18](#atomics.types.float-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5724)

*Effects*: Equivalent to: return fetch_*key*(operand) *op* operand;

[19](#atomics.types.float-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5728)

*Remarks*: If the result is not a representable value for its type ([[expr.pre]](expr.pre "7.1 Preamble"))
the result is unspecified, but the operations otherwise have no undefined
behavior[.](#atomics.types.float-19.sentence-1)

Atomic arithmetic operations on *floating-point-type* should conform to the std​::​numeric_limits<*floating-point-type*> traits associated with the floating-point type ([[limits.syn]](limits.syn "17.3.3 Header <limits> synopsis"))[.](#atomics.types.float-19.sentence-2)

The floating-point environment ([[cfenv]](cfenv "29.3 The floating-point environment")) for atomic arithmetic operations
on *floating-point-type* may be different than the
calling thread's floating-point environment[.](#atomics.types.float-19.sentence-3)

#### [32.5.8.5](#atomics.types.pointer) Partial specialization for pointers [[atomics.types.pointer]](atomics.types.pointer)

namespace std {template<class T> struct atomic<T*> {using value_type = T*; using difference_type = ptrdiff_t; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const volatile noexcept; bool is_lock_free() const noexcept; constexpr atomic() noexcept; constexpr atomic(T*) noexcept;
 atomic(const atomic&) = delete;
 atomic& operator=(const atomic&) = delete;
 atomic& operator=(const atomic&) volatile = delete; void store(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store(T*, memory_order = memory_order::seq_cst) noexcept;
 T* operator=(T*) volatile noexcept; constexpr T* operator=(T*) noexcept;
 T* load(memory_order = memory_order::seq_cst) const volatile noexcept; constexpr T* load(memory_order = memory_order::seq_cst) const noexcept; operator T*() const volatile noexcept; constexpr operator T*() const noexcept;

 T* exchange(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T* exchange(T*, memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_weak(T*&, T*, memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_weak(T*&, T*, memory_order, memory_order) noexcept; bool compare_exchange_strong(T*&, T*, memory_order, memory_order) volatile noexcept; constexpr bool compare_exchange_strong(T*&, T*, memory_order, memory_order) noexcept; bool compare_exchange_weak(T*&, T*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_weak(T*&, T*,
 memory_order = memory_order::seq_cst) noexcept; bool compare_exchange_strong(T*&, T*,
 memory_order = memory_order::seq_cst) volatile noexcept; constexpr bool compare_exchange_strong(T*&, T*,
 memory_order = memory_order::seq_cst) noexcept;

 T* fetch_add(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T* fetch_add(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept;
 T* fetch_sub(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T* fetch_sub(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept;
 T* fetch_max(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T* fetch_max(T*, memory_order = memory_order::seq_cst) noexcept;
 T* fetch_min(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr T* fetch_min(T*, memory_order = memory_order::seq_cst) noexcept; void store_add(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_add(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept; void store_sub(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_sub(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept; void store_max(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_max(T*, memory_order = memory_order::seq_cst) noexcept; void store_min(T*, memory_order = memory_order::seq_cst) volatile noexcept; constexpr void store_min(T*, memory_order = memory_order::seq_cst) noexcept;

 T* operator++(int) volatile noexcept; constexpr T* operator++(int) noexcept;
 T* operator--(int) volatile noexcept; constexpr T* operator--(int) noexcept;
 T* operator++() volatile noexcept; constexpr T* operator++() noexcept;
 T* operator--() volatile noexcept; constexpr T* operator--() noexcept;
 T* operator+=(ptrdiff_t) volatile noexcept; constexpr T* operator+=(ptrdiff_t) noexcept;
 T* operator-=(ptrdiff_t) volatile noexcept; constexpr T* operator-=(ptrdiff_t) noexcept; void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept; constexpr void wait(T*, memory_order = memory_order::seq_cst) const noexcept; void notify_one() volatile noexcept; constexpr void notify_one() noexcept; void notify_all() volatile noexcept; constexpr void notify_all() noexcept; };}

[1](#atomics.types.pointer-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5825)

There is a partial specialization of the atomic class template for pointers[.](#atomics.types.pointer-1.sentence-1)

Specializations of this partial specialization are standard-layout structs[.](#atomics.types.pointer-1.sentence-2)

They each have a trivial destructor[.](#atomics.types.pointer-1.sentence-3)

[2](#atomics.types.pointer-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5830)

Descriptions are provided below only for members that differ from the primary template[.](#atomics.types.pointer-2.sentence-1)

[3](#atomics.types.pointer-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5833)

The following operations perform pointer arithmetic[.](#atomics.types.pointer-3.sentence-1)

The correspondence among key, operator, and computation is specified
in Table [156](#tab:atomic.types.pointer.comp "Table 156: Atomic pointer computations")[.](#atomics.types.pointer-3.sentence-2)

Table [156](#tab:atomic.types.pointer.comp) — Atomic pointer computations [[tab:atomic.types.pointer.comp]](./tab:atomic.types.pointer.comp)  

| [ð](#tab:atomic.types.pointer.comp-row-1)<br>***key*** | **Op** | **Computation** | ***key*** | **Op** | **Computation** |
| --- | --- | --- | --- | --- | --- |
| [ð](#tab:atomic.types.pointer.comp-row-2)<br>add | + | addition | sub | - | subtraction |
| [ð](#tab:atomic.types.pointer.comp-row-3)<br>max |  | maximum | min |  | minimum |

[ð](#lib:atomic_fetch_add__)

`T* fetch_key(ptrdiff_t operand, memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr T* fetch_key(ptrdiff_t operand, memory_order order = memory_order::seq_cst) noexcept;
`

[4](#atomics.types.pointer-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5879)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.pointer-4.sentence-1)

[5](#atomics.types.pointer-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5884)

*Mandates*: T is a complete object type[.](#atomics.types.pointer-5.sentence-1)

[*Note [1](#atomics.types.pointer-note-1)*:

Pointer arithmetic on void* or function pointers is ill-formed[.](#atomics.types.pointer-5.sentence-2)

â *end note*]

[6](#atomics.types.pointer-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5891)

*Effects*: Atomically replaces the value pointed to bythis with the result of the computation applied to the
value pointed to by this and the given operand[.](#atomics.types.pointer-6.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.pointer-6.sentence-2)

These operations are atomic read-modify-write operations ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#atomics.types.pointer-6.sentence-3)

[7](#atomics.types.pointer-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5899)

*Returns*: Atomically, the value pointed to by this immediately before the effects[.](#atomics.types.pointer-7.sentence-1)

[8](#atomics.types.pointer-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5903)

*Remarks*: The result may be an undefined address,
but the operations otherwise have no undefined behavior[.](#atomics.types.pointer-8.sentence-1)

[9](#atomics.types.pointer-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5908)

For fetch_max and fetch_min, the maximum and minimum
computation is performed as if by max and min algorithms ([[alg.min.max]](alg.min.max "26.8.9 Minimum and maximum")), respectively, with the object value and the first
parameter as the arguments[.](#atomics.types.pointer-9.sentence-1)

[*Note [2](#atomics.types.pointer-note-2)*:

If the pointers point to different complete objects (or subobjects thereof),
the < operator does not establish a strict weak ordering
(Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"), [[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#atomics.types.pointer-9.sentence-2)

â *end note*]

[ð](#lib:atomic_store_add_)

`void store_key(see above operand, memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr void store_key(see above operand, memory_order order = memory_order::seq_cst) noexcept;
`

[10](#atomics.types.pointer-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5939)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.pointer-10.sentence-1)

[11](#atomics.types.pointer-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5944)

*Mandates*: T is a complete object type[.](#atomics.types.pointer-11.sentence-1)

[*Note [3](#atomics.types.pointer-note-3)*:

Pointer arithmetic on void* or function pointers is ill-formed[.](#atomics.types.pointer-11.sentence-2)

â *end note*]

[12](#atomics.types.pointer-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5951)

*Effects*: Atomically replaces the value pointed to by this with the result of the computation applied to
the value pointed to by this and the given operand[.](#atomics.types.pointer-12.sentence-1)

Memory is affected according to the value of order[.](#atomics.types.pointer-12.sentence-2)

These operations are atomic modify-write operations ([[atomics.order]](atomics.order "32.5.4 Order and consistency"))[.](#atomics.types.pointer-12.sentence-3)

[13](#atomics.types.pointer-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5959)

*Remarks*: The result may be an undefined address,
but the operations otherwise have no undefined behavior[.](#atomics.types.pointer-13.sentence-1)

For store_max and store_min,
the maximum and minimum computation is performed
as if by max and min algorithms ([[alg.min.max]](alg.min.max "26.8.9 Minimum and maximum")), respectively,
with the value pointed to by this and
the first parameter as the arguments[.](#atomics.types.pointer-13.sentence-2)

[*Note [4](#atomics.types.pointer-note-4)*:

If the pointers point to different complete objects (or subobjects thereof),
the < operator does not establish
a strict weak ordering (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"), [[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#atomics.types.pointer-13.sentence-3)

â *end note*]

[ð](#lib:operator+=,atomic%3cT*%3e__)

`T* operator op=(ptrdiff_t operand) volatile noexcept;
constexpr T* operator op=(ptrdiff_t operand) noexcept;
`

[14](#atomics.types.pointer-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5983)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.pointer-14.sentence-1)

[15](#atomics.types.pointer-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L5988)

*Effects*: Equivalent to: return fetch_*key*(operand) *op* operand;

#### [32.5.8.6](#atomics.types.memop) Member operators common to integers and pointers to objects [[atomics.types.memop]](atomics.types.memop)

[ð](#lib:operator++,atomic%3cT*%3e)

`value_type operator++(int) volatile noexcept;
constexpr value_type operator++(int) noexcept;
`

[1](#atomics.types.memop-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6003)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.memop-1.sentence-1)

[2](#atomics.types.memop-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6008)

*Effects*: Equivalent to: return fetch_add(1);

[ð](#lib:operator--,atomic%3cT*%3e)

`value_type operator--(int) volatile noexcept;
constexpr value_type operator--(int) noexcept;
`

[3](#atomics.types.memop-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6021)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.memop-3.sentence-1)

[4](#atomics.types.memop-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6026)

*Effects*: Equivalent to: return fetch_sub(1);

[ð](#lib:operator++,atomic%3cT*%3e_)

`value_type operator++() volatile noexcept;
constexpr value_type operator++() noexcept;
`

[5](#atomics.types.memop-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6039)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.memop-5.sentence-1)

[6](#atomics.types.memop-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6044)

*Effects*: Equivalent to: return fetch_add(1) + 1;

[ð](#lib:operator--,atomic%3cT*%3e_)

`value_type operator--() volatile noexcept;
constexpr value_type operator--() noexcept;
`

[7](#atomics.types.memop-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6057)

*Constraints*: For the volatile overload of this function,is_always_lock_free is true[.](#atomics.types.memop-7.sentence-1)

[8](#atomics.types.memop-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6062)

*Effects*: Equivalent to: return fetch_sub(1) - 1;

#### [32.5.8.7](#util.smartptr.atomic) Partial specializations for smart pointers [[util.smartptr.atomic]](util.smartptr.atomic)

#### [32.5.8.7.1](#util.smartptr.atomic.general) General [[util.smartptr.atomic.general]](util.smartptr.atomic.general)

[1](#util.smartptr.atomic.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6072)

The library provides partial specializations of the atomic template
for shared-ownership smart pointers ([[util.sharedptr]](util.sharedptr "20.3.2 Shared-ownership pointers"))[.](#util.smartptr.atomic.general-1.sentence-1)

[*Note [1](#util.smartptr.atomic.general-note-1)*:

The partial specializations are declared in header [<memory>](memory.syn#header:%3cmemory%3e "20.2.2 Header <memory> synopsis [memory.syn]")[.](#util.smartptr.atomic.general-1.sentence-2)

â *end note*]

The behavior of all operations is as specified in [atomics.types.generic],
unless specified otherwise[.](#util.smartptr.atomic.general-1.sentence-3)

The template parameter T of these partial specializations
may be an incomplete type[.](#util.smartptr.atomic.general-1.sentence-4)

[2](#util.smartptr.atomic.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6083)

All changes to an atomic smart pointer in [[util.smartptr.atomic]](#util.smartptr.atomic "32.5.8.7 Partial specializations for smart pointers"), and
all associated use_count increments,
are guaranteed to be performed atomically[.](#util.smartptr.atomic.general-2.sentence-1)

Associated use_count decrements
are sequenced after the atomic operation,
but are not required to be part of it[.](#util.smartptr.atomic.general-2.sentence-2)

Any associated deletion and deallocation
are sequenced after the atomic update step and
are not part of the atomic operation[.](#util.smartptr.atomic.general-2.sentence-3)

[*Note [2](#util.smartptr.atomic.general-note-2)*:

If the atomic operation uses locks,
locks acquired by the implementation
will be held when any use_count adjustments are performed, and
will not be held when any destruction or deallocation
resulting from this is performed[.](#util.smartptr.atomic.general-2.sentence-4)

â *end note*]

[3](#util.smartptr.atomic.general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6101)

[*Example [1](#util.smartptr.atomic.general-example-1)*: template<typename T> class atomic_list {struct node { T t;
 shared_ptr<node> next; };
 atomic<shared_ptr<node>> head;

public: shared_ptr<node> find(T t) const {auto p = head.load(); while (p && p->t != t) p = p->next; return p; }void push_front(T t) {auto p = make_shared<node>();
 p->t = t;
 p->next = head; while (!head.compare_exchange_weak(p->next, p)) {}}}; â *end example*]

#### [32.5.8.7.2](#util.smartptr.atomic.shared) Partial specialization for shared_ptr [[util.smartptr.atomic.shared]](util.smartptr.atomic.shared)

[ð](#lib:atomic%3cshared_ptr%3cT%3e%3e)

namespace std {template<class T> struct atomic<shared_ptr<T>> {using value_type = shared_ptr<T>; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const noexcept; constexpr atomic() noexcept; constexpr atomic(nullptr_t) noexcept : atomic() { }constexpr atomic(shared_ptr<T> desired) noexcept;
 atomic(const atomic&) = delete; void operator=(const atomic&) = delete; constexpr shared_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept; constexpr operator shared_ptr<T>() const noexcept; constexpr void store(shared_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr void operator=(shared_ptr<T> desired) noexcept; constexpr void operator=(nullptr_t) noexcept; constexpr shared_ptr<T> exchange(shared_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired,
 memory_order success, memory_order failure) noexcept; constexpr bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired,
 memory_order success, memory_order failure) noexcept; constexpr bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr void wait(shared_ptr<T> old,
 memory_order order = memory_order::seq_cst) const noexcept; constexpr void notify_one() noexcept; constexpr void notify_all() noexcept; private: shared_ptr<T> p; // *exposition only*};}

[ð](#lib:atomic%3cshared_ptr%3cT%3e%3e,constructor)

`constexpr atomic() noexcept;
`

[1](#util.smartptr.atomic.shared-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6181)

*Effects*: Value-initializes p[.](#util.smartptr.atomic.shared-1.sentence-1)

[ð](#lib:atomic%3cshared_ptr%3cT%3e%3e,constructor_)

`constexpr atomic(shared_ptr<T> desired) noexcept;
`

[2](#util.smartptr.atomic.shared-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6192)

*Effects*: Initializes the object with the value desired[.](#util.smartptr.atomic.shared-2.sentence-1)

Initialization is not an atomic operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#util.smartptr.atomic.shared-2.sentence-2)

[*Note [1](#util.smartptr.atomic.shared-note-1)*:

It is possible to have an access to
an atomic object A race with its construction,
for example,
by communicating the address of the just-constructed object A to another thread via memory_order​::​relaxed operations
on a suitable atomic pointer variable, and
then immediately accessing A in the receiving thread[.](#util.smartptr.atomic.shared-2.sentence-3)

This results in undefined behavior[.](#util.smartptr.atomic.shared-2.sentence-4)

â *end note*]

[ð](#lib:store,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr void store(shared_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
`

[3](#util.smartptr.atomic.shared-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6214)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​release, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.shared-3.sentence-1)

[4](#util.smartptr.atomic.shared-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6221)

*Effects*: Atomically replaces the value pointed to by this with
the value of desired as if by p.swap(desired)[.](#util.smartptr.atomic.shared-4.sentence-1)

Memory is affected according to the value of order[.](#util.smartptr.atomic.shared-4.sentence-2)

[ð](#lib:operator=,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr void operator=(shared_ptr<T> desired) noexcept;
`

[5](#util.smartptr.atomic.shared-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6234)

*Effects*: Equivalent to store(desired)[.](#util.smartptr.atomic.shared-5.sentence-1)

[ð](#lib:operator=,atomic%3cshared_ptr%3cT%3e%3e_)

`constexpr void operator=(nullptr_t) noexcept;
`

[6](#util.smartptr.atomic.shared-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6245)

*Effects*: Equivalent to store(nullptr)[.](#util.smartptr.atomic.shared-6.sentence-1)

[ð](#lib:load,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr shared_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
`

[7](#util.smartptr.atomic.shared-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6256)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.shared-7.sentence-1)

[8](#util.smartptr.atomic.shared-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6263)

*Effects*: Memory is affected according to the value of order[.](#util.smartptr.atomic.shared-8.sentence-1)

[9](#util.smartptr.atomic.shared-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6267)

*Returns*: Atomically returns p[.](#util.smartptr.atomic.shared-9.sentence-1)

[ð](#lib:operator_shared_ptr%3cT%3e,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr operator shared_ptr<T>() const noexcept;
`

[10](#util.smartptr.atomic.shared-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6278)

*Effects*: Equivalent to: return load();

[ð](#lib:exchange,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr shared_ptr<T> exchange(shared_ptr<T> desired,
                                 memory_order order = memory_order::seq_cst) noexcept;
`

[11](#util.smartptr.atomic.shared-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6290)

*Effects*: Atomically replaces p with desired as if by p.swap(desired)[.](#util.smartptr.atomic.shared-11.sentence-1)

Memory is affected according to the value of order[.](#util.smartptr.atomic.shared-11.sentence-2)

This is an atomic read-modify-write operation ([[intro.races]](intro.races "6.10.2.2 Data races"))[.](#util.smartptr.atomic.shared-11.sentence-3)

[12](#util.smartptr.atomic.shared-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6297)

*Returns*: Atomically returns the value of p immediately before the effects[.](#util.smartptr.atomic.shared-12.sentence-1)

[ð](#lib:compare_exchange_weak,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired,
                                     memory_order success, memory_order failure) noexcept;
constexpr bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired,
                                       memory_order success, memory_order failure) noexcept;
`

[13](#util.smartptr.atomic.shared-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6312)

*Preconditions*: failure ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.shared-13.sentence-1)

[14](#util.smartptr.atomic.shared-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6319)

*Effects*: If p is equivalent to expected,
assigns desired to p and
has synchronization semantics corresponding to the value of success,
otherwise assigns p to expected and
has synchronization semantics corresponding to the value of failure[.](#util.smartptr.atomic.shared-14.sentence-1)

[15](#util.smartptr.atomic.shared-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6327)

*Returns*: true if p was equivalent to expected,false otherwise[.](#util.smartptr.atomic.shared-15.sentence-1)

[16](#util.smartptr.atomic.shared-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6332)

*Remarks*: Two shared_ptr objects are equivalent if
they store the same pointer value and
either share ownership or are both empty[.](#util.smartptr.atomic.shared-16.sentence-1)

The weak form may fail spuriously[.](#util.smartptr.atomic.shared-16.sentence-2)

See [[atomics.types.operations]](#atomics.types.operations "32.5.8.2 Operations on atomic types")[.](#util.smartptr.atomic.shared-16.sentence-3)

[17](#util.smartptr.atomic.shared-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6339)

If the operation returns true,expected is not accessed after the atomic update and
the operation is an atomic read-modify-write operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))
on the memory pointed to by this[.](#util.smartptr.atomic.shared-17.sentence-1)

Otherwise, the operation is an atomic load operation on that memory, andexpected is updated with the existing value
read from the atomic object in the attempted atomic update[.](#util.smartptr.atomic.shared-17.sentence-2)

The use_count update corresponding to the write to expected is part of the atomic operation[.](#util.smartptr.atomic.shared-17.sentence-3)

The write to expected itself
is not required to be part of the atomic operation[.](#util.smartptr.atomic.shared-17.sentence-4)

[ð](#lib:compare_exchange_weak,atomic%3cshared_ptr%3cT%3e%3e_)

`constexpr bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired,
                                     memory_order order = memory_order::seq_cst) noexcept;
`

[18](#util.smartptr.atomic.shared-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6360)

*Effects*: Equivalent to:return compare_exchange_weak(expected, desired, order, fail_order); where fail_order is the same as order except that a value of memory_order​::​acq_rel shall be replaced by the value memory_order​::​acquire and
a value of memory_order​::​release shall be replaced by the value memory_order​::​relaxed[.](#util.smartptr.atomic.shared-18.sentence-1)

[ð](#lib:compare_exchange_strong,atomic%3cshared_ptr%3cT%3e%3e_)

`constexpr bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired,
                                       memory_order order = memory_order::seq_cst) noexcept;
`

[19](#util.smartptr.atomic.shared-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6380)

*Effects*: Equivalent to:return compare_exchange_strong(expected, desired, order, fail_order); where fail_order is the same as order except that a value of memory_order​::​acq_rel shall be replaced by the value memory_order​::​acquire and
a value of memory_order​::​release shall be replaced by the value memory_order​::​relaxed[.](#util.smartptr.atomic.shared-19.sentence-1)

[ð](#lib:wait,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr void wait(shared_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
`

[20](#util.smartptr.atomic.shared-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6399)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.shared-20.sentence-1)

[21](#util.smartptr.atomic.shared-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6406)

*Effects*: Repeatedly performs the following steps, in order:

- [(21.1)](#util.smartptr.atomic.shared-21.1)

  Evaluates load(order) and compares it to old[.](#util.smartptr.atomic.shared-21.1.sentence-1)

- [(21.2)](#util.smartptr.atomic.shared-21.2)

  If the two are not equivalent, returns[.](#util.smartptr.atomic.shared-21.2.sentence-1)

- [(21.3)](#util.smartptr.atomic.shared-21.3)

  Blocks until it
 is unblocked by an atomic notifying operation or is unblocked spuriously[.](#util.smartptr.atomic.shared-21.3.sentence-1)

[22](#util.smartptr.atomic.shared-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6419)

*Remarks*: Two shared_ptr objects are equivalent
if they store the same pointer and either share ownership or are both empty[.](#util.smartptr.atomic.shared-22.sentence-1)

This function is an atomic waiting operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.shared-22.sentence-2)

[ð](#lib:notify_one,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr void notify_one() noexcept;
`

[23](#util.smartptr.atomic.shared-23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6432)

*Effects*: Unblocks the execution of at least one atomic waiting operation
that is eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call,
if any such atomic waiting operations exist[.](#util.smartptr.atomic.shared-23.sentence-1)

[24](#util.smartptr.atomic.shared-24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6438)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.shared-24.sentence-1)

[ð](#lib:notify_all,atomic%3cshared_ptr%3cT%3e%3e)

`constexpr void notify_all() noexcept;
`

[25](#util.smartptr.atomic.shared-25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6449)

*Effects*: Unblocks the execution of all atomic waiting operations
that are eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call[.](#util.smartptr.atomic.shared-25.sentence-1)

[26](#util.smartptr.atomic.shared-26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6454)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.shared-26.sentence-1)

#### [32.5.8.7.3](#util.smartptr.atomic.weak) Partial specialization for weak_ptr [[util.smartptr.atomic.weak]](util.smartptr.atomic.weak)

[ð](#lib:atomic%3cweak_ptr%3cT%3e%3e)

namespace std {template<class T> struct atomic<weak_ptr<T>> {using value_type = weak_ptr<T>; static constexpr bool is_always_lock_free = *implementation-defined*; bool is_lock_free() const noexcept; constexpr atomic() noexcept; constexpr atomic(weak_ptr<T> desired) noexcept;
 atomic(const atomic&) = delete; void operator=(const atomic&) = delete; constexpr weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept; constexpr operator weak_ptr<T>() const noexcept; constexpr void store(weak_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr void operator=(weak_ptr<T> desired) noexcept; constexpr weak_ptr<T> exchange(weak_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
 memory_order success, memory_order failure) noexcept; constexpr bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
 memory_order success, memory_order failure) noexcept; constexpr bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
 memory_order order = memory_order::seq_cst) noexcept; constexpr void wait(weak_ptr<T> old,
 memory_order order = memory_order::seq_cst) const noexcept; constexpr void notify_one() noexcept; constexpr void notify_all() noexcept; private: weak_ptr<T> p; // *exposition only*};}

[ð](#lib:atomic%3cweak_ptr%3cT%3e%3e,constructor)

`constexpr atomic() noexcept;
`

[1](#util.smartptr.atomic.weak-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6509)

*Effects*: Value-initializes p[.](#util.smartptr.atomic.weak-1.sentence-1)

[ð](#lib:atomic%3cweak_ptr%3cT%3e%3e,constructor_)

`constexpr atomic(weak_ptr<T> desired) noexcept;
`

[2](#util.smartptr.atomic.weak-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6520)

*Effects*: Initializes the object with the value desired[.](#util.smartptr.atomic.weak-2.sentence-1)

Initialization is not an atomic operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))[.](#util.smartptr.atomic.weak-2.sentence-2)

[*Note [1](#util.smartptr.atomic.weak-note-1)*:

It is possible to have an access to
an atomic object A race with its construction,
for example,
by communicating the address of the just-constructed object A to another thread via memory_order​::​relaxed operations
on a suitable atomic pointer variable, and
then immediately accessing A in the receiving thread[.](#util.smartptr.atomic.weak-2.sentence-3)

This results in undefined behavior[.](#util.smartptr.atomic.weak-2.sentence-4)

â *end note*]

[ð](#lib:store,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr void store(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
`

[3](#util.smartptr.atomic.weak-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6542)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​release, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.weak-3.sentence-1)

[4](#util.smartptr.atomic.weak-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6549)

*Effects*: Atomically replaces the value pointed to by this with
the value of desired as if by p.swap(desired)[.](#util.smartptr.atomic.weak-4.sentence-1)

Memory is affected according to the value of order[.](#util.smartptr.atomic.weak-4.sentence-2)

[ð](#lib:operator=,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr void operator=(weak_ptr<T> desired) noexcept;
`

[5](#util.smartptr.atomic.weak-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6562)

*Effects*: Equivalent to store(desired)[.](#util.smartptr.atomic.weak-5.sentence-1)

[ð](#lib:load,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
`

[6](#util.smartptr.atomic.weak-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6573)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.weak-6.sentence-1)

[7](#util.smartptr.atomic.weak-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6580)

*Effects*: Memory is affected according to the value of order[.](#util.smartptr.atomic.weak-7.sentence-1)

[8](#util.smartptr.atomic.weak-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6584)

*Returns*: Atomically returns p[.](#util.smartptr.atomic.weak-8.sentence-1)

[ð](#lib:operator_weak_ptr%3cT%3e,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr operator weak_ptr<T>() const noexcept;
`

[9](#util.smartptr.atomic.weak-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6595)

*Effects*: Equivalent to: return load();

[ð](#lib:exchange,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr weak_ptr<T> exchange(weak_ptr<T> desired,
                               memory_order order = memory_order::seq_cst) noexcept;
`

[10](#util.smartptr.atomic.weak-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6607)

*Effects*: Atomically replaces p with desired as if by p.swap(desired)[.](#util.smartptr.atomic.weak-10.sentence-1)

Memory is affected according to the value of order[.](#util.smartptr.atomic.weak-10.sentence-2)

This is an atomic read-modify-write operation ([[intro.races]](intro.races "6.10.2.2 Data races"))[.](#util.smartptr.atomic.weak-10.sentence-3)

[11](#util.smartptr.atomic.weak-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6614)

*Returns*: Atomically returns the value of p immediately before the effects[.](#util.smartptr.atomic.weak-11.sentence-1)

[ð](#lib:compare_exchange_weak,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
                                     memory_order success, memory_order failure) noexcept;
constexpr bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
                                       memory_order success, memory_order failure) noexcept;
`

[12](#util.smartptr.atomic.weak-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6628)

*Preconditions*: failure ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.weak-12.sentence-1)

[13](#util.smartptr.atomic.weak-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6635)

*Effects*: If p is equivalent to expected,
assigns desired to p and
has synchronization semantics corresponding to the value of success,
otherwise assigns p to expected and
has synchronization semantics corresponding to the value of failure[.](#util.smartptr.atomic.weak-13.sentence-1)

[14](#util.smartptr.atomic.weak-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6643)

*Returns*: true if p was equivalent to expected,false otherwise[.](#util.smartptr.atomic.weak-14.sentence-1)

[15](#util.smartptr.atomic.weak-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6648)

*Remarks*: Two weak_ptr objects are equivalent if
they store the same pointer value and
either share ownership or are both empty[.](#util.smartptr.atomic.weak-15.sentence-1)

The weak form may fail spuriously[.](#util.smartptr.atomic.weak-15.sentence-2)

See [[atomics.types.operations]](#atomics.types.operations "32.5.8.2 Operations on atomic types")[.](#util.smartptr.atomic.weak-15.sentence-3)

[16](#util.smartptr.atomic.weak-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6655)

If the operation returns true,expected is not accessed after the atomic update and
the operation is an atomic read-modify-write operation ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))
on the memory pointed to by this[.](#util.smartptr.atomic.weak-16.sentence-1)

Otherwise, the operation is an atomic load operation on that memory, andexpected is updated with the existing value
read from the atomic object in the attempted atomic update[.](#util.smartptr.atomic.weak-16.sentence-2)

The use_count update corresponding to the write to expected is part of the atomic operation[.](#util.smartptr.atomic.weak-16.sentence-3)

The write to expected itself
is not required to be part of the atomic operation[.](#util.smartptr.atomic.weak-16.sentence-4)

[ð](#lib:compare_exchange_weak,atomic%3cweak_ptr%3cT%3e%3e_)

`constexpr bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
                                     memory_order order = memory_order::seq_cst) noexcept;
`

[17](#util.smartptr.atomic.weak-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6676)

*Effects*: Equivalent to:return compare_exchange_weak(expected, desired, order, fail_order); where fail_order is the same as order except that a value of memory_order​::​acq_rel shall be replaced by the value memory_order​::​acquire and
a value of memory_order​::​release shall be replaced by the value memory_order​::​relaxed[.](#util.smartptr.atomic.weak-17.sentence-1)

[ð](#lib:compare_exchange_strong,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
                                       memory_order order = memory_order::seq_cst) noexcept;
`

[18](#util.smartptr.atomic.weak-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6696)

*Effects*: Equivalent to:return compare_exchange_strong(expected, desired, order, fail_order); where fail_order is the same as order except that a value of memory_order​::​acq_rel shall be replaced by the value memory_order​::​acquire and
a value of memory_order​::​release shall be replaced by the value memory_order​::​relaxed[.](#util.smartptr.atomic.weak-18.sentence-1)

[ð](#lib:wait,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr void wait(weak_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
`

[19](#util.smartptr.atomic.weak-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6715)

*Preconditions*: order ismemory_order​::​relaxed,memory_order​::​acquire, ormemory_order​::​seq_cst[.](#util.smartptr.atomic.weak-19.sentence-1)

[20](#util.smartptr.atomic.weak-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6722)

*Effects*: Repeatedly performs the following steps, in order:

- [(20.1)](#util.smartptr.atomic.weak-20.1)

  Evaluates load(order) and compares it to old[.](#util.smartptr.atomic.weak-20.1.sentence-1)

- [(20.2)](#util.smartptr.atomic.weak-20.2)

  If the two are not equivalent, returns[.](#util.smartptr.atomic.weak-20.2.sentence-1)

- [(20.3)](#util.smartptr.atomic.weak-20.3)

  Blocks until it
 is unblocked by an atomic notifying operation or is unblocked spuriously[.](#util.smartptr.atomic.weak-20.3.sentence-1)

[21](#util.smartptr.atomic.weak-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6735)

*Remarks*: Two weak_ptr objects are equivalent
if they store the same pointer and either share ownership or are both empty[.](#util.smartptr.atomic.weak-21.sentence-1)

This function is an atomic waiting operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.weak-21.sentence-2)

[ð](#lib:notify_one,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr void notify_one() noexcept;
`

[22](#util.smartptr.atomic.weak-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6749)

*Effects*: Unblocks the execution of at least one atomic waiting operation
that is eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call,
if any such atomic waiting operations exist[.](#util.smartptr.atomic.weak-22.sentence-1)

[23](#util.smartptr.atomic.weak-23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6755)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.weak-23.sentence-1)

[ð](#lib:notify_all,atomic%3cweak_ptr%3cT%3e%3e)

`constexpr void notify_all() noexcept;
`

[24](#util.smartptr.atomic.weak-24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6766)

*Effects*: Unblocks the execution of all atomic waiting operations
that are eligible to be unblocked ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying")) by this call[.](#util.smartptr.atomic.weak-24.sentence-1)

[25](#util.smartptr.atomic.weak-25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6771)

*Remarks*: This function is an atomic notifying operation ([[atomics.wait]](atomics.wait "32.5.6 Waiting and notifying"))[.](#util.smartptr.atomic.weak-25.sentence-1)
