From Jason Turner

[thread.lock.unique]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpp_mbt8e5/{from.md → to.md} +63 -75
tmp/tmpp_mbt8e5/{from.md → to.md} RENAMED
@@ -48,12 +48,10 @@ namespace std {
48
  private:
49
  mutex_type* pm; // exposition only
50
  bool owns; // exposition only
51
  };
52
 
53
- template<class Mutex> unique_lock(unique_lock<Mutex>) -> unique_lock<Mutex>;
54
-
55
  template<class Mutex>
56
  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
57
  }
58
  ```
59
 
@@ -62,123 +60,113 @@ object within a scope. Ownership of the lockable object may be acquired
62
  at construction or after construction, and may be transferred, after
63
  acquisition, to another `unique_lock` object. Objects of type
64
  `unique_lock` are not copyable but are movable. The behavior of a
65
  program is undefined if the contained pointer `pm` is not null and the
66
  lockable object pointed to by `pm` does not exist for the entire
67
- remaining lifetime ([[basic.life]]) of the `unique_lock` object. The
68
- supplied `Mutex` type shall meet the `BasicLockable` requirements (
69
- [[thread.req.lockable.basic]]).
70
 
71
- [*Note 1*: `unique_lock<Mutex>` meets the `BasicLockable` requirements.
72
- If `Mutex` meets the `Lockable` requirements (
73
- [[thread.req.lockable.req]]), `unique_lock<Mutex>` also meets the
74
- `Lockable` requirements; if `Mutex` meets the `TimedLockable`
75
- requirements ([[thread.req.lockable.timed]]), `unique_lock<Mutex>` also
76
- meets the `TimedLockable` requirements. — *end note*]
77
 
78
- ##### `unique_lock` constructors, destructor, and assignment <a id="thread.lock.unique.cons">[[thread.lock.unique.cons]]</a>
79
 
80
  ``` cpp
81
  unique_lock() noexcept;
82
  ```
83
 
84
- *Effects:* Constructs an object of type `unique_lock`.
85
-
86
- *Postconditions:* `pm == 0` and `owns == false`.
87
 
88
  ``` cpp
89
  explicit unique_lock(mutex_type& m);
90
  ```
91
 
92
- *Requires:* If `mutex_type` is not a recursive mutex the calling thread
93
- does not own the mutex.
94
 
95
- *Effects:* Constructs an object of type `unique_lock` and calls
96
- `m.lock()`.
97
 
98
- *Postconditions:* `pm == addressof(m)` and `owns == true`.
99
 
100
  ``` cpp
101
  unique_lock(mutex_type& m, defer_lock_t) noexcept;
102
  ```
103
 
104
- *Effects:* Constructs an object of type `unique_lock`.
105
-
106
- *Postconditions:* `pm == addressof(m)` and `owns == false`.
107
 
108
  ``` cpp
109
  unique_lock(mutex_type& m, try_to_lock_t);
110
  ```
111
 
112
- *Requires:* The supplied `Mutex` type shall meet the `Lockable`
113
- requirements ([[thread.req.lockable.req]]). If `mutex_type` is not a
114
  recursive mutex the calling thread does not own the mutex.
115
 
116
- *Effects:* Constructs an object of type `unique_lock` and calls
117
- `m.try_lock()`.
118
 
119
- *Postconditions:* `pm == addressof(m)` and `owns == res`, where `res` is
120
- the value returned by the call to `m.try_lock()`.
121
 
122
  ``` cpp
123
  unique_lock(mutex_type& m, adopt_lock_t);
124
  ```
125
 
126
- *Requires:* The calling thread owns the mutex.
127
 
128
- *Effects:* Constructs an object of type `unique_lock`.
129
-
130
- *Postconditions:* `pm == addressof(m)` and `owns == true`.
131
 
132
  *Throws:* Nothing.
133
 
134
  ``` cpp
135
  template<class Clock, class Duration>
136
  unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
137
  ```
138
 
139
- *Requires:* If `mutex_type` is not a recursive mutex the calling thread
140
- does not own the mutex. The supplied `Mutex` type shall meet the
141
- `TimedLockable` requirements ([[thread.req.lockable.timed]]).
142
 
143
- *Effects:* Constructs an object of type `unique_lock` and calls
144
- `m.try_lock_until(abs_time)`.
145
 
146
- *Postconditions:* `pm == addressof(m)` and `owns == res`, where `res` is
147
- the value returned by the call to `m.try_lock_until(abs_time)`.
148
 
149
  ``` cpp
150
  template<class Rep, class Period>
151
  unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
152
  ```
153
 
154
- *Requires:* If `mutex_type` is not a recursive mutex the calling thread
155
- does not own the mutex. The supplied `Mutex` type shall meet the
156
- `TimedLockable` requirements ([[thread.req.lockable.timed]]).
157
 
158
- *Effects:* Constructs an object of type `unique_lock` and calls
159
- `m.try_lock_for(rel_time)`.
160
 
161
- *Postconditions:* `pm == addressof(m)` and `owns == res`, where `res` is
162
- the value returned by the call to `m.try_lock_for(rel_time)`.
163
 
164
  ``` cpp
165
  unique_lock(unique_lock&& u) noexcept;
166
  ```
167
 
168
- *Postconditions:* `pm == u_p.pm` and `owns == u_p.owns` (where `u_p` is
169
- the state of `u` just prior to this construction), `u.pm == 0` and
170
  `u.owns == false`.
171
 
172
  ``` cpp
173
  unique_lock& operator=(unique_lock&& u);
174
  ```
175
 
176
  *Effects:* If `owns` calls `pm->unlock()`.
177
 
178
- *Postconditions:* `pm == u_p.pm` and `owns == u_p.owns` (where `u_p` is
179
- the state of `u` just prior to this construction), `u.pm == 0` and
180
  `u.owns == false`.
181
 
182
  [*Note 1*: With a recursive mutex it is possible for both `*this` and
183
  `u` to own the same mutex before the assignment. In this case, `*this`
184
  will own the mutex after the assignment and `u` will not. — *end note*]
@@ -189,44 +177,44 @@ will own the mutex after the assignment and `u` will not. — *end note*]
189
  ~unique_lock();
190
  ```
191
 
192
  *Effects:* If `owns` calls `pm->unlock()`.
193
 
194
- ##### `unique_lock` locking <a id="thread.lock.unique.locking">[[thread.lock.unique.locking]]</a>
195
 
196
  ``` cpp
197
  void lock();
198
  ```
199
 
200
  *Effects:* As if by `pm->lock()`.
201
 
202
- *Postconditions:* `owns == true`.
203
 
204
  *Throws:* Any exception thrown by `pm->lock()`. `system_error` when an
205
- exception is required ([[thread.req.exception]]).
206
 
207
  *Error conditions:*
208
 
209
  - `operation_not_permitted` — if `pm` is `nullptr`.
210
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
211
 
212
  ``` cpp
213
  bool try_lock();
214
  ```
215
 
216
- *Requires:* The supplied `Mutex` shall meet the `Lockable`
217
- requirements ([[thread.req.lockable.req]]).
218
 
219
  *Effects:* As if by `pm->try_lock()`.
220
 
221
  *Returns:* The value returned by the call to `try_lock()`.
222
 
223
- *Postconditions:* `owns == res`, where `res` is the value returned by
224
- the call to `try_lock()`.
225
 
226
  *Throws:* Any exception thrown by `pm->try_lock()`. `system_error` when
227
- an exception is required ([[thread.req.exception]]).
228
 
229
  *Error conditions:*
230
 
231
  - `operation_not_permitted` — if `pm` is `nullptr`.
232
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
@@ -234,22 +222,22 @@ an exception is required ([[thread.req.exception]]).
234
  ``` cpp
235
  template<class Clock, class Duration>
236
  bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
237
  ```
238
 
239
- *Requires:* The supplied `Mutex` type shall meet the `TimedLockable`
240
- requirements ([[thread.req.lockable.timed]]).
241
 
242
  *Effects:* As if by `pm->try_lock_until(abs_time)`.
243
 
244
  *Returns:* The value returned by the call to `try_lock_until(abs_time)`.
245
 
246
- *Postconditions:* `owns == res`, where `res` is the value returned by
247
- the call to `try_lock_until(abs_time)`.
248
 
249
  *Throws:* Any exception thrown by `pm->try_lock_until()`. `system_error`
250
- when an exception is required ([[thread.req.exception]]).
251
 
252
  *Error conditions:*
253
 
254
  - `operation_not_permitted` — if `pm` is `nullptr`.
255
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
@@ -257,22 +245,22 @@ when an exception is required ([[thread.req.exception]]).
257
  ``` cpp
258
  template<class Rep, class Period>
259
  bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
260
  ```
261
 
262
- *Requires:* The supplied `Mutex` type shall meet the `TimedLockable`
263
- requirements ([[thread.req.lockable.timed]]).
264
 
265
  *Effects:* As if by `pm->try_lock_for(rel_time)`.
266
 
267
- *Returns:* The value returned by the call to `try_lock_until(rel_time)`.
268
 
269
- *Postconditions:* `owns == res`, where `res` is the value returned by
270
- the call to `try_lock_for(rel_time)`.
271
 
272
  *Throws:* Any exception thrown by `pm->try_lock_for()`. `system_error`
273
- when an exception is required ([[thread.req.exception]]).
274
 
275
  *Error conditions:*
276
 
277
  - `operation_not_permitted` — if `pm` is `nullptr`.
278
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
@@ -281,20 +269,20 @@ when an exception is required ([[thread.req.exception]]).
281
  void unlock();
282
  ```
283
 
284
  *Effects:* As if by `pm->unlock()`.
285
 
286
- *Postconditions:* `owns == false`.
287
 
288
  *Throws:* `system_error` when an exception is
289
- required ([[thread.req.exception]]).
290
 
291
  *Error conditions:*
292
 
293
  - `operation_not_permitted` — if on entry `owns` is `false`.
294
 
295
- ##### `unique_lock` modifiers <a id="thread.lock.unique.mod">[[thread.lock.unique.mod]]</a>
296
 
297
  ``` cpp
298
  void swap(unique_lock& u) noexcept;
299
  ```
300
 
@@ -304,20 +292,20 @@ void swap(unique_lock& u) noexcept;
304
  mutex_type* release() noexcept;
305
  ```
306
 
307
  *Returns:* The previous value of `pm`.
308
 
309
- *Postconditions:* `pm == 0` and `owns == false`.
310
 
311
  ``` cpp
312
  template<class Mutex>
313
  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
314
  ```
315
 
316
  *Effects:* As if by `x.swap(y)`.
317
 
318
- ##### `unique_lock` observers <a id="thread.lock.unique.obs">[[thread.lock.unique.obs]]</a>
319
 
320
  ``` cpp
321
  bool owns_lock() const noexcept;
322
  ```
323
 
 
48
  private:
49
  mutex_type* pm; // exposition only
50
  bool owns; // exposition only
51
  };
52
 
 
 
53
  template<class Mutex>
54
  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
55
  }
56
  ```
57
 
 
60
  at construction or after construction, and may be transferred, after
61
  acquisition, to another `unique_lock` object. Objects of type
62
  `unique_lock` are not copyable but are movable. The behavior of a
63
  program is undefined if the contained pointer `pm` is not null and the
64
  lockable object pointed to by `pm` does not exist for the entire
65
+ remaining lifetime [[basic.life]] of the `unique_lock` object. The
66
+ supplied `Mutex` type shall meet the *Cpp17BasicLockable* requirements
67
+ [[thread.req.lockable.basic]].
68
 
69
+ [*Note 1*: `unique_lock<Mutex>` meets the *Cpp17BasicLockable*
70
+ requirements. If `Mutex` meets the *Cpp17Lockable* requirements
71
+ [[thread.req.lockable.req]], `unique_lock<Mutex>` also meets the
72
+ *Cpp17Lockable* requirements; if `Mutex` meets the *Cpp17TimedLockable*
73
+ requirements [[thread.req.lockable.timed]], `unique_lock<Mutex>` also
74
+ meets the *Cpp17TimedLockable* requirements. — *end note*]
75
 
76
+ ##### Constructors, destructor, and assignment <a id="thread.lock.unique.cons">[[thread.lock.unique.cons]]</a>
77
 
78
  ``` cpp
79
  unique_lock() noexcept;
80
  ```
81
 
82
+ *Ensures:* `pm == 0` and `owns == false`.
 
 
83
 
84
  ``` cpp
85
  explicit unique_lock(mutex_type& m);
86
  ```
87
 
88
+ *Preconditions:* If `mutex_type` is not a recursive mutex the calling
89
+ thread does not own the mutex.
90
 
91
+ *Effects:* Calls `m.lock()`.
 
92
 
93
+ *Ensures:* `pm == addressof(m)` and `owns == true`.
94
 
95
  ``` cpp
96
  unique_lock(mutex_type& m, defer_lock_t) noexcept;
97
  ```
98
 
99
+ *Ensures:* `pm == addressof(m)` and `owns == false`.
 
 
100
 
101
  ``` cpp
102
  unique_lock(mutex_type& m, try_to_lock_t);
103
  ```
104
 
105
+ *Preconditions:* The supplied `Mutex` type meets the *Cpp17Lockable*
106
+ requirements [[thread.req.lockable.req]]. If `mutex_type` is not a
107
  recursive mutex the calling thread does not own the mutex.
108
 
109
+ *Effects:* Calls `m.try_lock()`.
 
110
 
111
+ *Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
112
+ value returned by the call to `m.try_lock()`.
113
 
114
  ``` cpp
115
  unique_lock(mutex_type& m, adopt_lock_t);
116
  ```
117
 
118
+ *Preconditions:* The calling thread owns the mutex.
119
 
120
+ *Ensures:* `pm == addressof(m)` and `owns == true`.
 
 
121
 
122
  *Throws:* Nothing.
123
 
124
  ``` cpp
125
  template<class Clock, class Duration>
126
  unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
127
  ```
128
 
129
+ *Preconditions:* If `mutex_type` is not a recursive mutex the calling
130
+ thread does not own the mutex. The supplied `Mutex` type meets the
131
+ *Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
132
 
133
+ *Effects:* Calls `m.try_lock_until(abs_time)`.
 
134
 
135
+ *Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
136
+ value returned by the call to `m.try_lock_until(abs_time)`.
137
 
138
  ``` cpp
139
  template<class Rep, class Period>
140
  unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
141
  ```
142
 
143
+ *Preconditions:* If `mutex_type` is not a recursive mutex the calling
144
+ thread does not own the mutex. The supplied `Mutex` type meets the
145
+ *Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
146
 
147
+ *Effects:* Calls `m.try_lock_for(rel_time)`.
 
148
 
149
+ *Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
150
+ value returned by the call to `m.try_lock_for(rel_time)`.
151
 
152
  ``` cpp
153
  unique_lock(unique_lock&& u) noexcept;
154
  ```
155
 
156
+ *Ensures:* `pm == u_p.pm` and `owns == u_p.owns` (where `u_p` is the
157
+ state of `u` just prior to this construction), `u.pm == 0` and
158
  `u.owns == false`.
159
 
160
  ``` cpp
161
  unique_lock& operator=(unique_lock&& u);
162
  ```
163
 
164
  *Effects:* If `owns` calls `pm->unlock()`.
165
 
166
+ *Ensures:* `pm == u_p.pm` and `owns == u_p.owns` (where `u_p` is the
167
+ state of `u` just prior to this construction), `u.pm == 0` and
168
  `u.owns == false`.
169
 
170
  [*Note 1*: With a recursive mutex it is possible for both `*this` and
171
  `u` to own the same mutex before the assignment. In this case, `*this`
172
  will own the mutex after the assignment and `u` will not. — *end note*]
 
177
  ~unique_lock();
178
  ```
179
 
180
  *Effects:* If `owns` calls `pm->unlock()`.
181
 
182
+ ##### Locking <a id="thread.lock.unique.locking">[[thread.lock.unique.locking]]</a>
183
 
184
  ``` cpp
185
  void lock();
186
  ```
187
 
188
  *Effects:* As if by `pm->lock()`.
189
 
190
+ *Ensures:* `owns == true`.
191
 
192
  *Throws:* Any exception thrown by `pm->lock()`. `system_error` when an
193
+ exception is required [[thread.req.exception]].
194
 
195
  *Error conditions:*
196
 
197
  - `operation_not_permitted` — if `pm` is `nullptr`.
198
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
199
 
200
  ``` cpp
201
  bool try_lock();
202
  ```
203
 
204
+ *Preconditions:* The supplied `Mutex` meets the *Cpp17Lockable*
205
+ requirements [[thread.req.lockable.req]].
206
 
207
  *Effects:* As if by `pm->try_lock()`.
208
 
209
  *Returns:* The value returned by the call to `try_lock()`.
210
 
211
+ *Ensures:* `owns == res`, where `res` is the value returned by the call
212
+ to `try_lock()`.
213
 
214
  *Throws:* Any exception thrown by `pm->try_lock()`. `system_error` when
215
+ an exception is required [[thread.req.exception]].
216
 
217
  *Error conditions:*
218
 
219
  - `operation_not_permitted` — if `pm` is `nullptr`.
220
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
 
222
  ``` cpp
223
  template<class Clock, class Duration>
224
  bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
225
  ```
226
 
227
+ *Preconditions:* The supplied `Mutex` type meets the
228
+ *Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
229
 
230
  *Effects:* As if by `pm->try_lock_until(abs_time)`.
231
 
232
  *Returns:* The value returned by the call to `try_lock_until(abs_time)`.
233
 
234
+ *Ensures:* `owns == res`, where `res` is the value returned by the call
235
+ to `try_lock_until(abs_time)`.
236
 
237
  *Throws:* Any exception thrown by `pm->try_lock_until()`. `system_error`
238
+ when an exception is required [[thread.req.exception]].
239
 
240
  *Error conditions:*
241
 
242
  - `operation_not_permitted` — if `pm` is `nullptr`.
243
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
 
245
  ``` cpp
246
  template<class Rep, class Period>
247
  bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
248
  ```
249
 
250
+ *Preconditions:* The supplied `Mutex` type meets the
251
+ *Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
252
 
253
  *Effects:* As if by `pm->try_lock_for(rel_time)`.
254
 
255
+ *Returns:* The value returned by the call to `try_lock_for(rel_time)`.
256
 
257
+ *Ensures:* `owns == res`, where `res` is the value returned by the call
258
+ to `try_lock_for(rel_time)`.
259
 
260
  *Throws:* Any exception thrown by `pm->try_lock_for()`. `system_error`
261
+ when an exception is required [[thread.req.exception]].
262
 
263
  *Error conditions:*
264
 
265
  - `operation_not_permitted` — if `pm` is `nullptr`.
266
  - `resource_deadlock_would_occur` — if on entry `owns` is `true`.
 
269
  void unlock();
270
  ```
271
 
272
  *Effects:* As if by `pm->unlock()`.
273
 
274
+ *Ensures:* `owns == false`.
275
 
276
  *Throws:* `system_error` when an exception is
277
+ required [[thread.req.exception]].
278
 
279
  *Error conditions:*
280
 
281
  - `operation_not_permitted` — if on entry `owns` is `false`.
282
 
283
+ ##### Modifiers <a id="thread.lock.unique.mod">[[thread.lock.unique.mod]]</a>
284
 
285
  ``` cpp
286
  void swap(unique_lock& u) noexcept;
287
  ```
288
 
 
292
  mutex_type* release() noexcept;
293
  ```
294
 
295
  *Returns:* The previous value of `pm`.
296
 
297
+ *Ensures:* `pm == 0` and `owns == false`.
298
 
299
  ``` cpp
300
  template<class Mutex>
301
  void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
302
  ```
303
 
304
  *Effects:* As if by `x.swap(y)`.
305
 
306
+ ##### Observers <a id="thread.lock.unique.obs">[[thread.lock.unique.obs]]</a>
307
 
308
  ``` cpp
309
  bool owns_lock() const noexcept;
310
  ```
311