[util.smartptr.atomic.general]

# 32 Concurrency support library [[thread]](./#thread)

## 32.5 Atomic operations [[atomics]](atomics#util.smartptr.atomic.general)

### 32.5.8 Class template atomic [[atomics.types.generic]](atomics.types.generic#util.smartptr.atomic.general)

#### 32.5.8.7 Partial specializations for smart pointers [[util.smartptr.atomic]](util.smartptr.atomic#general)

#### 32.5.8.7.1 General [util.smartptr.atomic.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6072)

The library provides partial specializations of the atomic template
for shared-ownership smart pointers ([[util.sharedptr]](util.sharedptr "20.3.2 Shared-ownership pointers"))[.](#1.sentence-1)

[*Note [1](#note-1)*:

The partial specializations are declared in header [<memory>](memory.syn#header:%3cmemory%3e "20.2.2 Header <memory> synopsis [memory.syn]")[.](#1.sentence-2)

â *end note*]

The behavior of all operations is as specified in [[atomics.types.generic]](atomics.types.generic "32.5.8 Class template atomic"),
unless specified otherwise[.](#1.sentence-3)

The template parameter T of these partial specializations
may be an incomplete type[.](#1.sentence-4)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6083)

All changes to an atomic smart pointer in [[util.smartptr.atomic]](util.smartptr.atomic "32.5.8.7 Partial specializations for smart pointers"), and
all associated use_count increments,
are guaranteed to be performed atomically[.](#2.sentence-1)

Associated use_count decrements
are sequenced after the atomic operation,
but are not required to be part of it[.](#2.sentence-2)

Any associated deletion and deallocation
are sequenced after the atomic update step and
are not part of the atomic operation[.](#2.sentence-3)

[*Note [2](#note-2)*:

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[.](#2.sentence-4)

â *end note*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L6101)

[*Example [1](#example-1)*: template<typename T> class atomic_list {struct node { T t;
 shared_ptr<node> next; };
 atomic<shared_ptr<node>> head;

public: shared_ptr<node> find(T t) const {auto p = head.load(); while (p && p->t != t) p = p->next; return 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*]
