Atomically compares the underlying
expected, and if they are equivalent, replaces the former with
desired (performs read-modify-write operation). Otherwise, loads the actual value stored in
expected (performs load operation). The replacement is performed as if by the copy or move assignment operator of
shared_ptr, as appropriate.
shared_ptrs are equivalent if and only if they store the same pointer value and share ownership.
The memory models for the read-modify-write and load operations are
failure respectively. For overloads (3-4, 7-8),
order is used for both read-modify-write and load operations, except that std::memory_order_acquire and std::memory_order_relaxed are used for the load operation if order == std::memory_order_acq_rel, or order == std::memory_order_release respectively.
The weak versions (1-4) may fail spuriously.
|expected||-||reference 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|
|success||-||the memory synchronization ordering for the read-modify-write operation if the comparison succeeds. All values are permitted.|
|failure||-|| the memory synchronization 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 |
|order||-||the memory synchronization ordering for both operations|
 Return value
true if the underlying atomic value was changed, false otherwise.
All changes to the
atomic_shared_ptr object itself, and all associated use_count increments, are guaranteed to be performed atomically. Associated
use_count decrements take place after the atomic operation, but are not required to be part of it. Any associated destruction or deallocation operations take place after the atomic operation and are not part of it.
If the compare-exchange operation return true,
expected is not accessed after the atomic update step. If it returns false,
expected is updated with the existing value read from the
atomic_shared_ptr object in the attempted atomic update. The
use_count update corresponding to the write to
expected is part of the atomic operation, but the write to
expected itself is not required to be part of the atomic operation.
For overloads (1,3,5,7),
desired is not accessed after the atomic update step.
For overloads (2,4,6,8),
desired is moved from only if the compare-exchange operation returns true; the moving occurs after the atomic update step.
The weak forms (1-4) of the functions are allowed to fail spuriously, that is, act as if *this and expected are not equivalent even when they are. When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms.