function
<atomic>

std::atomic_compare_exchange_weak_explicit

template (1)
template <class T>
bool atomic_compare_exchange_weak_explicit (volatile atomic<T>* obj,
        T* expected, T val, memory_order success, memory_order failure) noexcept;
template <class T>
bool atomic_compare_exchange_weak_explicit (atomic<T>* obj,
        T* expected, T val, memory_order success, memory_order failure) noexcept;
overloads (2)
bool atomic_compare_exchange_weak_explicit (volatile A* obj,
        T* expected, T val, memory_order success, memory_order failure) noexcept;
bool atomic_compare_exchange_weak_explicit (A* obj,
        T* expected, T val, memory_order success, memory_order failure) noexcept;
Compare and exchange contained value (weak, explicit)
Operates like atomic_compare_exchange_weak, but it additionally allows to specify the memory order used both in case of success and failure.

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

Parameters

obj
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).
expected
Pointer to an object whose value is compared to the contained value, and which -in case it doesn't match- may be overwritten with the contained value.
T is the type of the value contained in the atomic object (atomic's template parameter).
val
Value to copy to the contained object in case expected matches the contained value.
T is the type of the value contained in the atomic object (atomic's template parameter).
success
Synchronization mode for the operation in case expected matches the contained value.
This shall be a value of the enum type memory_order.
failure
Synchronization mode for the operation in case expected does not match the contained value.
This shall be a value of the enum type memory_order that is neither memory_order_release nor memory_order_acq_rel, and which is not stronger than success.

Return value

true if *expected compares equal to the contained value (and does not fail spuriously).
false otherwise.

Data races

No data races (atomic operation). Memory order specified by arguments success and failure.

Exception safety

No-throw guarantee: never throws exceptions.

See also