From Jason Turner

[util.smartptr.atomic.weak]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpq8qjkirt/{from.md → to.md} +209 -0
tmp/tmpq8qjkirt/{from.md → to.md} RENAMED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Partial specialization for `weak_ptr` <a id="util.smartptr.atomic.weak">[[util.smartptr.atomic.weak]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ template<class T> struct atomic<weak_ptr<T>> {
6
+ using value_type = weak_ptr<T>;
7
+
8
+ static constexpr bool is_always_lock_free = implementation-defined // whether a given atomic type's operations are always lock free;
9
+ bool is_lock_free() const noexcept;
10
+
11
+ constexpr atomic() noexcept;
12
+ atomic(weak_ptr<T> desired) noexcept;
13
+ atomic(const atomic&) = delete;
14
+ void operator=(const atomic&) = delete;
15
+
16
+ weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
17
+ operator weak_ptr<T>() const noexcept;
18
+ void store(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
19
+ void operator=(weak_ptr<T> desired) noexcept;
20
+
21
+ weak_ptr<T> exchange(weak_ptr<T> desired,
22
+ memory_order order = memory_order::seq_cst) noexcept;
23
+ bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
24
+ memory_order success, memory_order failure) noexcept;
25
+ bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
26
+ memory_order success, memory_order failure) noexcept;
27
+ bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
28
+ memory_order order = memory_order::seq_cst) noexcept;
29
+ bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
30
+ memory_order order = memory_order::seq_cst) noexcept;
31
+
32
+ void wait(weak_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
33
+ void notify_one() noexcept;
34
+ void notify_all() noexcept;
35
+
36
+ private:
37
+ weak_ptr<T> p; // exposition only
38
+ };
39
+ }
40
+ ```
41
+
42
+ ``` cpp
43
+ constexpr atomic() noexcept;
44
+ ```
45
+
46
+ *Effects:* Initializes `p{}`.
47
+
48
+ ``` cpp
49
+ atomic(weak_ptr<T> desired) noexcept;
50
+ ```
51
+
52
+ *Effects:* Initializes the object with the value `desired`.
53
+ Initialization is not an atomic operation [[intro.multithread]].
54
+
55
+ [*Note 1*: It is possible to have an access to an atomic object `A`
56
+ race with its construction, for example, by communicating the address of
57
+ the just-constructed object `A` to another thread via
58
+ `memory_order::relaxed` operations on a suitable atomic pointer
59
+ variable, and then immediately accessing `A` in the receiving thread.
60
+ This results in undefined behavior. — *end note*]
61
+
62
+ ``` cpp
63
+ void store(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
64
+ ```
65
+
66
+ *Preconditions:* `order` is neither `memory_order::consume`,
67
+ `memory_order::acquire`, nor `memory_order::acq_rel`.
68
+
69
+ *Effects:* Atomically replaces the value pointed to by `this` with the
70
+ value of `desired` as if by `p.swap(desired)`. Memory is affected
71
+ according to the value of `order`.
72
+
73
+ ``` cpp
74
+ void operator=(weak_ptr<T> desired) noexcept;
75
+ ```
76
+
77
+ *Effects:* Equivalent to `store(desired)`.
78
+
79
+ ``` cpp
80
+ weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
81
+ ```
82
+
83
+ *Preconditions:* `order` is neither `memory_order::release` nor
84
+ `memory_order::acq_rel`.
85
+
86
+ *Effects:* Memory is affected according to the value of `order`.
87
+
88
+ *Returns:* Atomically returns `p`.
89
+
90
+ ``` cpp
91
+ operator weak_ptr<T>() const noexcept;
92
+ ```
93
+
94
+ *Effects:* Equivalent to: `return load();`
95
+
96
+ ``` cpp
97
+ weak_ptr<T> exchange(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
98
+ ```
99
+
100
+ *Effects:* Atomically replaces `p` with `desired` as if by
101
+ `p.swap(desired)`. Memory is affected according to the value of `order`.
102
+ This is an atomic read-modify-write operation [[intro.races]].
103
+
104
+ *Returns:* Atomically returns the value of `p` immediately before the
105
+ effects.
106
+
107
+ ``` cpp
108
+ bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
109
+ memory_order success, memory_order failure) noexcept;
110
+ bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
111
+ memory_order success, memory_order failure) noexcept;
112
+ ```
113
+
114
+ *Preconditions:* `failure` is neither `memory_order::release` nor
115
+ `memory_order::acq_rel`.
116
+
117
+ *Effects:* If `p` is equivalent to `expected`, assigns `desired` to `p`
118
+ and has synchronization semantics corresponding to the value of
119
+ `success`, otherwise assigns `p` to `expected` and has synchronization
120
+ semantics corresponding to the value of `failure`.
121
+
122
+ *Returns:* `true` if `p` was equivalent to `expected`, `false`
123
+ otherwise.
124
+
125
+ *Remarks:* Two `weak_ptr` objects are equivalent if they store the same
126
+ pointer value and either share ownership or are both empty. The weak
127
+ form may fail spuriously. See [[atomics.types.operations]].
128
+
129
+ If the operation returns `true`, `expected` is not accessed after the
130
+ atomic update and the operation is an atomic read-modify-write
131
+ operation [[intro.multithread]] on the memory pointed to by `this`.
132
+ Otherwise, the operation is an atomic load operation on that memory, and
133
+ `expected` is updated with the existing value read from the atomic
134
+ object in the attempted atomic update. The `use_count` update
135
+ corresponding to the write to `expected` is part of the atomic
136
+ operation. The write to `expected` itself is not required to be part of
137
+ the atomic operation.
138
+
139
+ ``` cpp
140
+ bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
141
+ memory_order order = memory_order::seq_cst) noexcept;
142
+ ```
143
+
144
+ *Effects:* Equivalent to:
145
+
146
+ ``` cpp
147
+ return compare_exchange_weak(expected, desired, order, fail_order);
148
+ ```
149
+
150
+ where `fail_order` is the same as `order` except that a value of
151
+ `memory_order::acq_rel` shall be replaced by the value
152
+ `memory_order::acquire` and a value of `memory_order::release` shall be
153
+ replaced by the value `memory_order::relaxed`.
154
+
155
+ ``` cpp
156
+ bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
157
+ memory_order order = memory_order::seq_cst) noexcept;
158
+ ```
159
+
160
+ *Effects:* Equivalent to:
161
+
162
+ ``` cpp
163
+ return compare_exchange_strong(expected, desired, order, fail_order);
164
+ ```
165
+
166
+ where `fail_order` is the same as `order` except that a value of
167
+ `memory_order::acq_rel` shall be replaced by the value
168
+ `memory_order::acquire` and a value of `memory_order::release` shall be
169
+ replaced by the value `memory_order::relaxed`.
170
+
171
+ ``` cpp
172
+ void wait(weak_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
173
+ ```
174
+
175
+ *Preconditions:* `order` is neither `memory_order::release` nor
176
+ `memory_order::acq_rel`.
177
+
178
+ *Effects:* Repeatedly performs the following steps, in order:
179
+
180
+ - Evaluates `load(order)` and compares it to `old`.
181
+ - If the two are not equivalent, returns.
182
+ - Blocks until it is unblocked by an atomic notifying operation or is
183
+ unblocked spuriously.
184
+
185
+ *Remarks:* Two `weak_ptr` objects are equivalent if they store the same
186
+ pointer and either share ownership or are both empty. This function is
187
+ an atomic waiting operation [[atomics.wait]].
188
+
189
+ ``` cpp
190
+ void notify_one() noexcept;
191
+ ```
192
+
193
+ *Effects:* Unblocks the execution of at least one atomic waiting
194
+ operation that is eligible to be unblocked [[atomics.wait]] by this
195
+ call, if any such atomic waiting operations exist.
196
+
197
+ *Remarks:* This function is an atomic notifying
198
+ operation [[atomics.wait]].
199
+
200
+ ``` cpp
201
+ void notify_all() noexcept;
202
+ ```
203
+
204
+ *Effects:* Unblocks the execution of all atomic waiting operations that
205
+ are eligible to be unblocked [[atomics.wait]] by this call.
206
+
207
+ *Remarks:* This function is an atomic notifying
208
+ operation [[atomics.wait]].
209
+