From Jason Turner

[util.smartptr.atomic.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpvjwkaq_6/{from.md → to.md} +55 -0
tmp/tmpvjwkaq_6/{from.md → to.md} RENAMED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##### General <a id="util.smartptr.atomic.general">[[util.smartptr.atomic.general]]</a>
2
+
3
+ The library provides partial specializations of the `atomic` template
4
+ for shared-ownership smart pointers [[util.sharedptr]].
5
+
6
+ [*Note 1*: The partial specializations are declared in header
7
+ `<memory>`. — *end note*]
8
+
9
+ The behavior of all operations is as specified in
10
+ [[atomics.types.generic]], unless specified otherwise. The template
11
+ parameter `T` of these partial specializations may be an incomplete
12
+ type.
13
+
14
+ All changes to an atomic smart pointer in [[util.smartptr.atomic]], and
15
+ all associated `use_count` increments, are guaranteed to be performed
16
+ atomically. Associated `use_count` decrements are sequenced after the
17
+ atomic operation, but are not required to be part of it. Any associated
18
+ deletion and deallocation are sequenced after the atomic update step and
19
+ are not part of the atomic operation.
20
+
21
+ [*Note 2*: If the atomic operation uses locks, locks acquired by the
22
+ implementation will be held when any `use_count` adjustments are
23
+ performed, and will not be held when any destruction or deallocation
24
+ resulting from this is performed. — *end note*]
25
+
26
+ [*Example 1*:
27
+
28
+ ``` cpp
29
+ template<typename T> class atomic_list {
30
+ struct node {
31
+ T t;
32
+ shared_ptr<node> next;
33
+ };
34
+ atomic<shared_ptr<node>> head;
35
+
36
+ public:
37
+ shared_ptr<node> find(T t) const {
38
+ auto p = head.load();
39
+ while (p && p->t != t)
40
+ p = p->next;
41
+
42
+ return p;
43
+ }
44
+
45
+ void push_front(T t) {
46
+ auto p = make_shared<node>();
47
+ p->t = t;
48
+ p->next = head;
49
+ while (!head.compare_exchange_weak(p->next, p)) {}
50
+ }
51
+ };
52
+ ```
53
+
54
+ — *end example*]
55
+