function
<atomic>

std::atomic_fetch_add_explicit

template (integral) (1)
template <class T>T atomic_fetch_add_explicit (volatile atomic<T>* obj,                             T val, memory_order sync) noexcept;template <class T>T atomic_fetch_add_explicit (atomic<T>* obj,                             T val, memory_order sync) noexcept;
template (pointer) (2)
template <class U>U* atomic_fetch_add_explicit (volatile atomic<U*>* obj,                              ptrdiff_t val, memory_order sync) noexcept;template <class U>U* atomic_fetch_add_explicit (atomic<U*>* obj,                              ptrdiff_t val, memory_order sync) noexcept;
overloads (3)
T atomic_fetch_add_explicit (volatile A* obj, M val, memory_order sync) noexcept;T atomic_fetch_add_explicit (A* obj, M val, memory_order sync) noexcept;
Add to contained value (explicit memory order)
Adds val the value contained in obj, using the memory order specified by sync.

The entire operation is atomic: the value cannot be modified between the instant its value is read (to be returned) and the moment it is modified by this function.

The function synchronizes using the memory order specified by argument sync.

See atomic::fetch_add for the equivalent member function of atomic.

Parameters

obj
Pointer to an atomic object that contains either an integral or a pointer value.
Type A represents other overloaded atomic types (in case the library does not implement the C-style atomic types as instantiations of atomic).
val
Value to add.
T is the type of the value contained by the atomic object (atomic's template parameter).
ptrdiff_t is a signed integral type.
M is T if T is an integral type, or ptrdiff_t if T is a pointer.
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 (or U*) is the type of the value contained by the atomic object (atomic's template parameter).

Data races

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

Exception safety

No-throw guarantee: never throws exceptions.

See also