tmp/tmp5855esom/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
#### Class template `unique_lock` <a id="thread.lock.unique">[[thread.lock.unique]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
template<class Mutex>
|
| 6 |
class unique_lock {
|
| 7 |
public:
|
|
@@ -47,13 +49,10 @@ namespace std {
|
|
| 47 |
|
| 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 |
|
| 58 |
An object of type `unique_lock` controls the ownership of a lockable
|
| 59 |
object within a scope. Ownership of the lockable object may be acquired
|
|
@@ -77,19 +76,16 @@ meets the *Cpp17TimedLockable* requirements. — *end note*]
|
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
unique_lock() noexcept;
|
| 80 |
```
|
| 81 |
|
| 82 |
-
*Ensures:* `pm ==
|
| 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
|
|
@@ -101,35 +97,33 @@ unique_lock(mutex_type& m, defer_lock_t) noexcept;
|
|
| 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]].
|
| 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
|
| 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:*
|
| 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
|
|
@@ -138,12 +132,11 @@ value returned by the call to `m.try_lock_until(abs_time)`.
|
|
| 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:*
|
| 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
|
|
@@ -204,14 +197,14 @@ bool try_lock();
|
|
| 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 |
-
*
|
|
|
|
| 210 |
|
| 211 |
-
*
|
| 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:*
|
|
@@ -227,17 +220,17 @@ template<class Clock, class Duration>
|
|
| 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 |
-
*
|
|
|
|
| 233 |
|
| 234 |
-
*
|
| 235 |
-
to `try_lock_until(abs_time)`.
|
| 236 |
|
| 237 |
-
*Throws:* Any exception thrown by `pm->try_lock_until()`.
|
| 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`.
|
|
@@ -250,17 +243,17 @@ template<class Rep, class Period>
|
|
| 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 |
-
*
|
|
|
|
| 256 |
|
| 257 |
-
*
|
| 258 |
-
to `try_lock_for(rel_time)`.
|
| 259 |
|
| 260 |
-
*Throws:* Any exception thrown by `pm->try_lock_for()`.
|
| 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`.
|
|
@@ -290,14 +283,14 @@ void swap(unique_lock& u) noexcept;
|
|
| 290 |
|
| 291 |
``` cpp
|
| 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 |
|
|
|
|
| 1 |
#### Class template `unique_lock` <a id="thread.lock.unique">[[thread.lock.unique]]</a>
|
| 2 |
|
| 3 |
+
##### General <a id="thread.lock.unique.general">[[thread.lock.unique.general]]</a>
|
| 4 |
+
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template<class Mutex>
|
| 8 |
class unique_lock {
|
| 9 |
public:
|
|
|
|
| 49 |
|
| 50 |
private:
|
| 51 |
mutex_type* pm; // exposition only
|
| 52 |
bool owns; // exposition only
|
| 53 |
};
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
```
|
| 56 |
|
| 57 |
An object of type `unique_lock` controls the ownership of a lockable
|
| 58 |
object within a scope. Ownership of the lockable object may be acquired
|
|
|
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
unique_lock() noexcept;
|
| 79 |
```
|
| 80 |
|
| 81 |
+
*Ensures:* `pm == nullptr` and `owns == false`.
|
| 82 |
|
| 83 |
``` cpp
|
| 84 |
explicit unique_lock(mutex_type& m);
|
| 85 |
```
|
| 86 |
|
|
|
|
|
|
|
|
|
|
| 87 |
*Effects:* Calls `m.lock()`.
|
| 88 |
|
| 89 |
*Ensures:* `pm == addressof(m)` and `owns == true`.
|
| 90 |
|
| 91 |
``` cpp
|
|
|
|
| 97 |
``` cpp
|
| 98 |
unique_lock(mutex_type& m, try_to_lock_t);
|
| 99 |
```
|
| 100 |
|
| 101 |
*Preconditions:* The supplied `Mutex` type meets the *Cpp17Lockable*
|
| 102 |
+
requirements [[thread.req.lockable.req]].
|
|
|
|
| 103 |
|
| 104 |
*Effects:* Calls `m.try_lock()`.
|
| 105 |
|
| 106 |
*Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
|
| 107 |
value returned by the call to `m.try_lock()`.
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
unique_lock(mutex_type& m, adopt_lock_t);
|
| 111 |
```
|
| 112 |
|
| 113 |
+
*Preconditions:* The calling thread holds a non-shared lock on `m`.
|
| 114 |
|
| 115 |
*Ensures:* `pm == addressof(m)` and `owns == true`.
|
| 116 |
|
| 117 |
*Throws:* Nothing.
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
template<class Clock, class Duration>
|
| 121 |
unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
|
| 122 |
```
|
| 123 |
|
| 124 |
+
*Preconditions:* The supplied `Mutex` type meets the
|
|
|
|
| 125 |
*Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
|
| 126 |
|
| 127 |
*Effects:* Calls `m.try_lock_until(abs_time)`.
|
| 128 |
|
| 129 |
*Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
|
|
|
|
| 132 |
``` cpp
|
| 133 |
template<class Rep, class Period>
|
| 134 |
unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
|
| 135 |
```
|
| 136 |
|
| 137 |
+
*Preconditions:* The supplied `Mutex` type meets the
|
|
|
|
| 138 |
*Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
|
| 139 |
|
| 140 |
*Effects:* Calls `m.try_lock_for(rel_time)`.
|
| 141 |
|
| 142 |
*Ensures:* `pm == addressof(m)` and `owns == res`, where `res` is the
|
|
|
|
| 197 |
*Preconditions:* The supplied `Mutex` meets the *Cpp17Lockable*
|
| 198 |
requirements [[thread.req.lockable.req]].
|
| 199 |
|
| 200 |
*Effects:* As if by `pm->try_lock()`.
|
| 201 |
|
| 202 |
+
*Ensures:* `owns == res`, where `res` is the value returned by
|
| 203 |
+
`pm->try_lock()`.
|
| 204 |
|
| 205 |
+
*Returns:* The value returned by `pm->try_lock()`.
|
|
|
|
| 206 |
|
| 207 |
*Throws:* Any exception thrown by `pm->try_lock()`. `system_error` when
|
| 208 |
an exception is required [[thread.req.exception]].
|
| 209 |
|
| 210 |
*Error conditions:*
|
|
|
|
| 220 |
*Preconditions:* The supplied `Mutex` type meets the
|
| 221 |
*Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
|
| 222 |
|
| 223 |
*Effects:* As if by `pm->try_lock_until(abs_time)`.
|
| 224 |
|
| 225 |
+
*Ensures:* `owns == res`, where `res` is the value returned by
|
| 226 |
+
`pm->try_lock_until(abs_time)`.
|
| 227 |
|
| 228 |
+
*Returns:* The value returned by `pm->try_lock_until(abs_time)`.
|
|
|
|
| 229 |
|
| 230 |
+
*Throws:* Any exception thrown by `pm->try_lock_until(abstime)`.
|
| 231 |
+
`system_error` when an exception is required [[thread.req.exception]].
|
| 232 |
|
| 233 |
*Error conditions:*
|
| 234 |
|
| 235 |
- `operation_not_permitted` — if `pm` is `nullptr`.
|
| 236 |
- `resource_deadlock_would_occur` — if on entry `owns` is `true`.
|
|
|
|
| 243 |
*Preconditions:* The supplied `Mutex` type meets the
|
| 244 |
*Cpp17TimedLockable* requirements [[thread.req.lockable.timed]].
|
| 245 |
|
| 246 |
*Effects:* As if by `pm->try_lock_for(rel_time)`.
|
| 247 |
|
| 248 |
+
*Ensures:* `owns == res`, where `res` is the value returned by
|
| 249 |
+
`pm->try_lock_for(rel_time)`.
|
| 250 |
|
| 251 |
+
*Returns:* The value returned by `pm->try_lock_for(rel_time)`.
|
|
|
|
| 252 |
|
| 253 |
+
*Throws:* Any exception thrown by `pm->try_lock_for(rel_time)`.
|
| 254 |
+
`system_error` when an exception is required [[thread.req.exception]].
|
| 255 |
|
| 256 |
*Error conditions:*
|
| 257 |
|
| 258 |
- `operation_not_permitted` — if `pm` is `nullptr`.
|
| 259 |
- `resource_deadlock_would_occur` — if on entry `owns` is `true`.
|
|
|
|
| 283 |
|
| 284 |
``` cpp
|
| 285 |
mutex_type* release() noexcept;
|
| 286 |
```
|
| 287 |
|
| 288 |
+
*Ensures:* `pm == 0` and `owns == false`.
|
| 289 |
+
|
| 290 |
*Returns:* The previous value of `pm`.
|
| 291 |
|
|
|
|
|
|
|
| 292 |
``` cpp
|
| 293 |
template<class Mutex>
|
| 294 |
void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
|
| 295 |
```
|
| 296 |
|