Atomically compare the value to an expected value, and store a new value if the values are equal. If the values were not equal, update the expected value with the value read.
bool compare_exchange_strong( shared_ptr<T>& expected,shared_ptr<T> new_value, memory_order order = std::memory_order_seq_cst) noexcept; bool compare_exchange_strong( shared_ptr<T>& expected,shared_ptr<T> new_value, memory_order success_order, memory_order failure_order) noexcept;
failure_order
shall
not be std::memory_order_release
or std::memory_order_acq_rel
.
Atomically compares expected
to the value stored in *this
and stores new_value
in *this
if equal, otherwise updates expected
to the value read.
true
if the existing
value of *this
was equal to expected
,
false
otherwise.
Nothing.
The 3-parameter overload is equivalent to the 4-parameter overload
with success_order==order
,
and failure_order==order
,
except that if order
is std::memory_order_acq_rel
, then failure_order
is std::memory_order_acquire
, and if
order
is std::memory_order_release
then failure_order
is std::memory_order_relaxed
.
This is an atomic read-modify-write operation for the memory location
comprising *this
if the result is true
,
with memory ordering success_order
,
otherwise it is an atomic load operation for the memory location
comprising *this
with memory ordering failure_order
.
#include <experimental/atomic>