std::atomic_compare_exchange_weak, std::atomic_compare_exchange_strong, std::atomic_compare_exchange_weak_explicit, std::atomic_compare_exchange_strong_explicit
Defined in header <atomic>
template< class T >
bool atomic_compare_exchange_weak_explicit( std::atomic<T>* obj,
template< class T >
bool atomic_compare_exchange_strong_explicit( std::atomic<T>* obj,
Atomically compares the value pointed to by
obj with the value pointed to by
expected, and if those are equal, replaces the former with
desired (performs read-modify-write operation). Otherwise, loads the actual value pointed to by
*expected (performs load operation).
The memory models for the read-modify-write and load operations are
fail respectively. The (1-2) versions use std::memory_order_seq_cst by default.
The weak forms ((1) and (3)) of the functions are allowed to fail spuriously, that is, act as if *obj != *expected even if they are equal. When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable.
These functions are defined in terms of member functions of std::atomic:
|obj||-||pointer to the atomic object to test and modify|
|expected||-||pointer to the value expected to be found in the atomic object|
|desired||-||the value to store in the atomic object if it is as expected|
|succ||-||the memory sycnhronization ordering for the read-modify-write operation if the comparison succeeds. All values are permitted.|
|fail||-|| the memory sycnhronization ordering for the load operation if the comparison fails. Cannot be std::memory_order_release or std::memory_order_acq_rel and cannot specify stronger ordering than |
 Return value
The result of the comparison: true if
*obj was equal to
*exp, false otherwise.
|This section is incomplete|
Reason: no example
 See also
| atomically compares the value of the atomic object with non-atomic argument and performs atomic exchange if equal or atomic load if not |
(public member function of
| atomically replaces the value of the atomic object with non-atomic argument and returns the old value of the atomic |
| specializes atomic operations for std::shared_ptr |
C documentation for atomic_compare_exchange, atomic_compare_exchange_explicit