From Jason Turner

[thread.lock.shared]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpxk2aa66s/{from.md → to.md} +309 -0
tmp/tmpxk2aa66s/{from.md → to.md} RENAMED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `shared_lock` <a id="thread.lock.shared">[[thread.lock.shared]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+
6
+ template <class Mutex>
7
+ class shared_lock {
8
+ public:
9
+ typedef Mutex mutex_type;
10
+
11
+ // Shared locking
12
+ shared_lock() noexcept;
13
+ explicit shared_lock(mutex_type& m); // blocking
14
+ shared_lock(mutex_type& m, defer_lock_t) noexcept;
15
+ shared_lock(mutex_type& m, try_to_lock_t);
16
+ shared_lock(mutex_type& m, adopt_lock_t);
17
+ template <class Clock, class Duration>
18
+ shared_lock(mutex_type& m,
19
+ const chrono::time_point<Clock, Duration>& abs_time);
20
+ template <class Rep, class Period>
21
+ shared_lock(mutex_type& m,
22
+ const chrono::duration<Rep, Period>& rel_time);
23
+ ~shared_lock();
24
+
25
+ shared_lock(shared_lock const&) = delete;
26
+ shared_lock& operator=(shared_lock const&) = delete;
27
+
28
+ shared_lock(shared_lock&& u) noexcept;
29
+ shared_lock& operator=(shared_lock&& u) noexcept;
30
+
31
+ void lock(); // blocking
32
+ bool try_lock();
33
+ template <class Rep, class Period>
34
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
35
+ template <class Clock, class Duration>
36
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
37
+ void unlock();
38
+
39
+ // Setters
40
+ void swap(shared_lock& u) noexcept;
41
+ mutex_type* release() noexcept;
42
+
43
+ // Getters
44
+ bool owns_lock() const noexcept;
45
+ explicit operator bool () const noexcept;
46
+ mutex_type* mutex() const noexcept;
47
+
48
+ private:
49
+ mutex_type* pm; // exposition only
50
+ bool owns; // exposition only
51
+ };
52
+
53
+ template <class Mutex>
54
+ void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
55
+
56
+ } // std
57
+ ```
58
+
59
+ An object of type `shared_lock` controls the shared ownership of a
60
+ lockable object within a scope. Shared ownership of the lockable object
61
+ may be acquired at construction or after construction, and may be
62
+ transferred, after acquisition, to another `shared_lock` object. Objects
63
+ of type `shared_lock` are not copyable but are movable. The behavior of
64
+ a program is undefined if the contained pointer `pm` is not null and the
65
+ lockable object pointed to by `pm` does not exist for the entire
66
+ remaining lifetime ([[basic.life]]) of the `shared_lock` object. The
67
+ supplied `Mutex` type shall meet the shared mutex requirements (
68
+ [[thread.sharedtimedmutex.requirements]]).
69
+
70
+ `shared_lock<Mutex>` meets the `TimedLockable` requirements (
71
+ [[thread.req.lockable.timed]]).
72
+
73
+ ##### `shared_lock` constructors, destructor, and assignment <a id="thread.lock.shared.cons">[[thread.lock.shared.cons]]</a>
74
+
75
+ ``` cpp
76
+ shared_lock() noexcept;
77
+ ```
78
+
79
+ *Effects:* Constructs an object of type `shared_lock`.
80
+
81
+ *Postconditions:* `pm == nullptr` and `owns == false`.
82
+
83
+ ``` cpp
84
+ explicit shared_lock(mutex_type& m);
85
+ ```
86
+
87
+ *Requires:* The calling thread does not own the mutex for any ownership
88
+ mode.
89
+
90
+ *Effects:* Constructs an object of type `shared_lock` and calls
91
+ `m.lock_shared()`.
92
+
93
+ *Postconditions:* `pm == &m` and `owns == true`.
94
+
95
+ ``` cpp
96
+ shared_lock(mutex_type& m, defer_lock_t) noexcept;
97
+ ```
98
+
99
+ *Effects:* Constructs an object of type `shared_lock`.
100
+
101
+ *Postconditions:* `pm == &m` and `owns == false`.
102
+
103
+ ``` cpp
104
+ shared_lock(mutex_type& m, try_to_lock_t);
105
+ ```
106
+
107
+ *Requires:* The calling thread does not own the mutex for any ownership
108
+ mode.
109
+
110
+ *Effects:* Constructs an object of type `shared_lock` and calls
111
+ `m.try_lock_shared()`.
112
+
113
+ *Postconditions:* `pm == &m` and `owns == res` where `res` is the value
114
+ returned by the call to `m.try_lock_shared()`.
115
+
116
+ ``` cpp
117
+ shared_lock(mutex_type& m, adopt_lock_t);
118
+ ```
119
+
120
+ *Requires:* The calling thread has shared ownership of the mutex.
121
+
122
+ *Effects:* Constructs an object of type `shared_lock`.
123
+
124
+ *Postconditions:* `pm == &m` and `owns == true`.
125
+
126
+ ``` cpp
127
+ template <class Clock, class Duration>
128
+ shared_lock(mutex_type& m,
129
+ const chrono::time_point<Clock, Duration>& abs_time);
130
+ ```
131
+
132
+ *Requires:* The calling thread does not own the mutex for any ownership
133
+ mode.
134
+
135
+ *Effects:* Constructs an object of type `shared_lock` and calls
136
+ `m.try_lock_shared_until(abs_time)`.
137
+
138
+ *Postconditions:* `pm == &m` and `owns == res` where `res` is the value
139
+ returned by the call to `m.try_lock_shared_until(abs_time)`.
140
+
141
+ ``` cpp
142
+ template <class Rep, class Period>
143
+ shared_lock(mutex_type& m,
144
+ const chrono::duration<Rep, Period>& rel_time);
145
+ ```
146
+
147
+ *Requires:* The calling thread does not own the mutex for any ownership
148
+ mode.
149
+
150
+ *Effects:* Constructs an object of type `shared_lock` and calls
151
+ `m.try_lock_shared_for(rel_time)`.
152
+
153
+ *Postconditions:* `pm == &m` and `owns == res` where `res` is the value
154
+ returned by the call to `m.try_lock_shared_for(rel_time)`.
155
+
156
+ ``` cpp
157
+ ~shared_lock();
158
+ ```
159
+
160
+ *Effects:* If `owns` calls `pm->unlock_shared()`.
161
+
162
+ ``` cpp
163
+ shared_lock(shared_lock&& sl) noexcept;
164
+ ```
165
+
166
+ *Postconditions:* `pm == &sl_p.pm` and `owns == sl_p.owns` (where `sl_p`
167
+ is the state of `sl` just prior to this construction),
168
+ `sl.pm == nullptr` and `sl.owns == false`.
169
+
170
+ ``` cpp
171
+ shared_lock& operator=(shared_lock&& sl) noexcept;
172
+ ```
173
+
174
+ *Effects:* If `owns` calls `pm->unlock_shared()`.
175
+
176
+ *Postconditions:* `pm == &sl_p.pm` and `owns == sl_p.owns` (where `sl_p`
177
+ is the state of `sl` just prior to this assignment), `sl.pm == nullptr`
178
+ and `sl.owns == false`.
179
+
180
+ ##### `shared_lock` locking <a id="thread.lock.shared.locking">[[thread.lock.shared.locking]]</a>
181
+
182
+ ``` cpp
183
+ void lock();
184
+ ```
185
+
186
+ *Effects:* `pm->lock_shared()`.
187
+
188
+ *Postconditions:* `owns == true`.
189
+
190
+ *Throws:* Any exception thrown by `pm->lock_shared()`. `system_error` if
191
+ an exception is required ([[thread.req.exception]]). `system_error`
192
+ with an error condition of `operation_not_permitted` if `pm` is
193
+ `nullptr`. `system_error` with an error condition of
194
+ `resource_deadlock_would_occur` if on entry `owns` is `true`.
195
+
196
+ ``` cpp
197
+ bool try_lock();
198
+ ```
199
+
200
+ *Effects:* `pm->try_lock_shared()`.
201
+
202
+ *Returns:* The value returned by the call to `pm->try_lock_shared()`.
203
+
204
+ *Postconditions:* `owns == res`, where `res` is the value returned by
205
+ the call to `pm->try_lock_shared()`.
206
+
207
+ *Throws:* Any exception thrown by `pm->try_lock_shared()`.
208
+ `system_error` if an exception is required ([[thread.req.exception]]).
209
+ `system_error` with an error condition of `operation_not_permitted` if
210
+ `pm` is `nullptr`. `system_error` with an error condition of
211
+ `resource_deadlock_would_occur` if on entry `owns` is `true`.
212
+
213
+ ``` cpp
214
+ template <class Clock, class Duration>
215
+ bool
216
+ try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
217
+ ```
218
+
219
+ *Effects:* `pm->try_lock_shared_until(abs_time)`.
220
+
221
+ *Returns:* The value returned by the call to
222
+ `pm->try_lock_shared_until(abs_time)`.
223
+
224
+ *Postconditions:* `owns == res`, where `res` is the value returned by
225
+ the call to `pm->try_lock_shared_until(abs_time)`.
226
+
227
+ *Throws:* Any exception thrown by `pm->try_lock_shared_until(abs_time)`.
228
+ `system_error` if an exception is required ([[thread.req.exception]]).
229
+ `system_error` with an error condition of `operation_not_permitted` if
230
+ `pm` is `nullptr`. `system_error` with an error condition of
231
+ `resource_deadlock_would_occur` if on entry `owns` is `true`.
232
+
233
+ ``` cpp
234
+ template <class Rep, class Period>
235
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
236
+ ```
237
+
238
+ *Effects:* `pm->try_lock_shared_for(rel_time)`.
239
+
240
+ *Returns:* The value returned by the call to
241
+ `pm->try_lock_shared_for(rel_time)`.
242
+
243
+ *Postconditions:* `owns == res`, where `res` is the value returned by
244
+ the call to `pm->try_lock_shared_for(rel_time)`.
245
+
246
+ *Throws:* Any exception thrown by `pm->try_lock_shared_for(rel_time)`.
247
+ `system_error` if an exception is required  ([[thread.req.exception]]).
248
+ `system_error` with an error condition of `operation_not_permitted` if
249
+ `pm` is `nullptr`. `system_error` with an error condition of
250
+ `resource_deadlock_would_occur` if on entry `owns` is `true`.
251
+
252
+ ``` cpp
253
+ void unlock();
254
+ ```
255
+
256
+ *Effects:* `pm->unlock_shared()`.
257
+
258
+ *Postconditions:* `owns == false`.
259
+
260
+ *Throws:* `system_error` when an exception is required
261
+  ([[thread.req.exception]]).
262
+
263
+ *Error conditions:*
264
+
265
+ - `operation_not_permitted` — if on entry `owns` is `false`.
266
+
267
+ ##### `shared_lock` modifiers <a id="thread.lock.shared.mod">[[thread.lock.shared.mod]]</a>
268
+
269
+ ``` cpp
270
+ void swap(shared_lock& sl) noexcept;
271
+ ```
272
+
273
+ *Effects:* Swaps the data members of `*this` and `sl`.
274
+
275
+ ``` cpp
276
+ mutex_type* release() noexcept;
277
+ ```
278
+
279
+ *Returns:* The previous value of `pm`.
280
+
281
+ *Postconditions:* `pm == nullptr` and `owns == false`.
282
+
283
+ ``` cpp
284
+ template <class Mutex>
285
+ void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
286
+ ```
287
+
288
+ *Effects:* `x.swap(y)`.
289
+
290
+ ##### `shared_lock` observers <a id="thread.lock.shared.obs">[[thread.lock.shared.obs]]</a>
291
+
292
+ ``` cpp
293
+ bool owns_lock() const noexcept;
294
+ ```
295
+
296
+ *Returns:* `owns`.
297
+
298
+ ``` cpp
299
+ explicit operator bool () const noexcept;
300
+ ```
301
+
302
+ *Returns:* `owns`.
303
+
304
+ ``` cpp
305
+ mutex_type* mutex() const noexcept;
306
+ ```
307
+
308
+ *Returns:* `pm`.
309
+