public member function
<atomic>

std::atomic::fetch_sub

if T is integral (1)
T fetch_sub (T val, memory_order sync = memory_order_seq_cst) volatile noexcept;
T fetch_sub (T val, memory_order sync = memory_order_seq_cst) noexcept;
if T is pointer (2)
T fetch_sub (ptrdiff_t val, memory_order sync = memory_order_seq_cst) volatile noexcept;
T fetch_sub (ptrdiff_t val, memory_order sync = memory_order_seq_cst) noexcept;
Subtract from contained value
Subtracts val from the contained value and returns the value it had immediately before the operation.

The entire operation is atomic (an atomic read-modify-write operation): the value is not affected by other threads between the instant its value is read (to be returned) and the moment it is modified by this function.

This member function is only defined in the atomic specializations for integral (1) and pointer (2) types (except for bool).

If the default value is used for the second argument, this function is equivalent to atomic::operator-=.

Parameters

val
Value to subtract.
T is atomic's template parameter (the type of the contained value).
ptrdiff_t is a signed integral type.
sync
Synchronization mode for the operation.
This shall be one of the values of the enum type memory_order.

Return value

The contained value before the call.
T is atomic's template parameter (the type of the contained value).

Data races

No data races (atomic operation). Memory order specified by argument sync.

Exception safety

No-throw guarantee: never throws exceptions.

See also