31 Atomic operations library [atomics]

31.8 Class template atomic [atomics.types.generic]

31.8.7 Partial specializations for smart pointers [util.smartptr.atomic]

31.8.7.1 General [util.smartptr.atomic.general]

The library provides partial specializations of the atomic template for shared-ownership smart pointers ([smartptr]).
The behavior of all operations is as specified in [atomics.types.generic], unless specified otherwise.
The template parameter T of these partial specializations may be an incomplete type.
All changes to an atomic smart pointer in [util.smartptr.atomic], and all associated use_­count increments, are guaranteed to be performed atomically.
Associated use_­count decrements are sequenced after the atomic operation, but are not required to be part of it.
Any associated deletion and deallocation are sequenced after the atomic update step and are not part of the atomic operation.
[Note 1:
If the atomic operation uses locks, locks acquired by the implementation will be held when any use_­count adjustments are performed, and will not be held when any destruction or deallocation resulting from this is performed.
— end note]
[Example 1: template<typename T> class atomic_list { struct node { T t; shared_ptr<node> next; }; atomic<shared_ptr<node>> head; public: auto find(T t) const { auto p = head.load(); while (p && p->t != t) p = p->next; return shared_ptr<node>(move(p)); } void push_front(T t) { auto p = make_shared<node>(); p->t = t; p->next = head; while (!head.compare_exchange_weak(p->next, p)) {} } }; — end example]