template <class T> T atomic_exchange (volatile atomic<T>* obj, T val) noexcept;
template <class T> T atomic_exchange (atomic<T>* obj, T val) noexcept;
T atomic_exchange (volatile A* obj, T val) noexcept;
T atomic_exchange (A* obj, T val) noexcept;
Read and modify contained value
Replaces the value contained in obj with val and returns the value obj had immediately before.
The entire operation is atomic (an atomic read-modify-write operation): the value of obj 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.
See atomic::exchange for the equivalent member function of atomic.
- Pointer to an atomic object.
Type A represents other overloaded atomic types (if the library does not implement the C-style atomic types as instantiations of atomic).
- Value to initialize the contained object with.
T is the type of the value contained in the atomic object (atomic's template parameter).
The value contained in obj before the call.
T is the type of the contained value (atomic's template parameter).
No data races (atomic operation). The operation uses sequential consistency (memory_order_seq_cst).
No-throw guarantee: never throws exceptions.