[util.smartptr.atomic.shared] (original) (raw)
32 Concurrency support library [thread]
32.5 Atomic operations [atomics]
32.5.8 Class template atomic [atomics.types.generic]
32.5.8.7 Partial specializations for smart pointers [util.smartptr.atomic]
32.5.8.7.2 Partial specialization for shared_ptr [util.smartptr.atomic.shared]
namespace std { template<class T> struct atomic<shared_ptr<T>> { using value_type = shared_ptr<T>;static constexpr bool is_always_lock_free = implementation-defined;bool is_lock_free() const noexcept;constexpr atomic() noexcept;constexpr atomic(nullptr_t) noexcept : atomic() { } atomic(shared_ptr<T> desired) noexcept; atomic(const atomic&) = delete;void operator=(const atomic&) = delete; shared_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;operator shared_ptr<T>() const noexcept;void store(shared_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;void operator=(shared_ptr<T> desired) noexcept;void operator=(nullptr_t) noexcept; shared_ptr<T> exchange(shared_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired, memory_order success, memory_order failure) noexcept;bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired, memory_order success, memory_order failure) noexcept;bool compare_exchange_weak(shared_ptr<T>& expected, shared_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;bool compare_exchange_strong(shared_ptr<T>& expected, shared_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;void wait(shared_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;void notify_one() noexcept;void notify_all() noexcept;private: shared_ptr<T> p; };}
Effects: Value-initializes p.
Effects: Initializes the object with the value desired.
[Note 1:
It is possible to have an access to an atomic object A race with its construction, for example, by communicating the address of the just-constructed object Ato another thread via memory_order::relaxed operations on a suitable atomic pointer variable, and then immediately accessing A in the receiving thread.
This results in undefined behavior.
— _end note_]
Preconditions: order ismemory_order::relaxed,memory_order::release, ormemory_order::seq_cst.
Effects: Atomically replaces the value pointed to by this with the value of desired as if by p.swap(desired).
Memory is affected according to the value of order.
Effects: Equivalent to store(desired).
Effects: Equivalent to store(nullptr).
Preconditions: order ismemory_order::relaxed,memory_order::acquire, ormemory_order::seq_cst.
Effects: Memory is affected according to the value of order.
Returns: Atomically returns p.
Effects: Equivalent to: return load();
Effects: Atomically replaces p with desiredas if by p.swap(desired).
Memory is affected according to the value of order.
This is an atomic read-modify-write operation ([intro.races]).
Returns: Atomically returns the value of p immediately before the effects.
Preconditions: failure ismemory_order::relaxed,memory_order::acquire, ormemory_order::
seq_cst.
Effects: If p is equivalent to expected, assigns desired to p and has synchronization semantics corresponding to the value of success, otherwise assigns p to expected and has synchronization semantics corresponding to the value of failure.
Returns: true if p was equivalent to expected,false otherwise.
Remarks: Two shared_ptr objects are equivalent if they store the same pointer value and either share ownership or are both empty.
The weak form may fail spuriously.
If the operation returns true,expected is not accessed after the atomic update and the operation is an atomic read-modify-write operation ([intro.multithread]) on the memory pointed to by this.
Otherwise, the operation is an atomic load operation on that memory, andexpected is updated with the existing value read from the atomic object in the attempted atomic update.
The use_count update corresponding to the write to expectedis part of the atomic operation.
The write to expected itself is not required to be part of the atomic operation.
Effects: Equivalent to:return compare_exchange_weak(expected, desired, order, fail_order);where fail_order is the same as orderexcept that a value of memory_order::acq_relshall be replaced by the value memory_order::acquire and a value of memory_order::releaseshall be replaced by the value memory_order::relaxed.
Effects: Equivalent to:return compare_exchange_strong(expected, desired, order, fail_order);where fail_order is the same as orderexcept that a value of memory_order::acq_relshall be replaced by the value memory_order::acquire and a value of memory_order::releaseshall be replaced by the value memory_order::relaxed.
Preconditions: order ismemory_order::relaxed,memory_order::acquire, ormemory_order::seq_cst.
Effects: Repeatedly performs the following steps, in order:
- Evaluates load(order) and compares it to old.
- If the two are not equivalent, returns.
- Blocks until it is unblocked by an atomic notifying operation or is unblocked spuriously.
Remarks: Two shared_ptr objects are equivalent if they store the same pointer and either share ownership or are both empty.
This function is an atomic waiting operation ([atomics.wait]).
Effects: Unblocks the execution of at least one atomic waiting operation that is eligible to be unblocked ([atomics.wait]) by this call, if any such atomic waiting operations exist.
Remarks: This function is an atomic notifying operation ([atomics.wait]).
Effects: Unblocks the execution of all atomic waiting operations that are eligible to be unblocked ([atomics.wait]) by this call.
Remarks: This function is an atomic notifying operation ([atomics.wait]).