tmp/tmpkbir3qu0/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Interruptible waits <a id="thread.condvarany.intwait">[[thread.condvarany.intwait]]</a>
|
| 2 |
+
|
| 3 |
+
The following wait functions will be notified when there is a stop
|
| 4 |
+
request on the passed `stop_token`. In that case the functions return
|
| 5 |
+
immediately, returning `false` if the predicate evaluates to `false`.
|
| 6 |
+
|
| 7 |
+
``` cpp
|
| 8 |
+
template<class Lock, class Predicate>
|
| 9 |
+
bool wait(Lock& lock, stop_token stoken, Predicate pred);
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
*Effects:* Registers for the duration of this call `*this` to get
|
| 13 |
+
notified on a stop request on `stoken` during this call and then
|
| 14 |
+
equivalent to:
|
| 15 |
+
|
| 16 |
+
``` cpp
|
| 17 |
+
while (!stoken.stop_requested()) {
|
| 18 |
+
if (pred())
|
| 19 |
+
return true;
|
| 20 |
+
wait(lock);
|
| 21 |
+
}
|
| 22 |
+
return pred();
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
[*Note 1*: The returned value indicates whether the predicate evaluated
|
| 26 |
+
to `true` regardless of whether there was a stop request. — *end note*]
|
| 27 |
+
|
| 28 |
+
*Ensures:* `lock` is locked by the calling thread.
|
| 29 |
+
|
| 30 |
+
*Remarks:* If the function fails to meet the postcondition, `terminate`
|
| 31 |
+
is called [[except.terminate]].
|
| 32 |
+
|
| 33 |
+
[*Note 2*: This can happen if the re-locking of the mutex throws an
|
| 34 |
+
exception. — *end note*]
|
| 35 |
+
|
| 36 |
+
*Throws:* Any exception thrown by `pred`.
|
| 37 |
+
|
| 38 |
+
``` cpp
|
| 39 |
+
template<class Lock, class Clock, class Duration, class Predicate>
|
| 40 |
+
bool wait_until(Lock& lock, stop_token stoken,
|
| 41 |
+
const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
*Effects:* Registers for the duration of this call `*this` to get
|
| 45 |
+
notified on a stop request on `stoken` during this call and then
|
| 46 |
+
equivalent to:
|
| 47 |
+
|
| 48 |
+
``` cpp
|
| 49 |
+
while (!stoken.stop_requested()) {
|
| 50 |
+
if (pred())
|
| 51 |
+
return true;
|
| 52 |
+
if (cv.wait_until(lock, abs_time) == cv_status::timeout)
|
| 53 |
+
return pred();
|
| 54 |
+
}
|
| 55 |
+
return pred();
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
[*Note 3*: There is no blocking if `pred()` is initially `true`,
|
| 59 |
+
`stoken.stop_requested()` was already `true` or the timeout has already
|
| 60 |
+
expired. — *end note*]
|
| 61 |
+
|
| 62 |
+
[*Note 4*: The returned value indicates whether the predicate evaluated
|
| 63 |
+
to `true` regardless of whether the timeout was triggered or a stop
|
| 64 |
+
request was made. — *end note*]
|
| 65 |
+
|
| 66 |
+
*Ensures:* `lock` is locked by the calling thread.
|
| 67 |
+
|
| 68 |
+
*Remarks:* If the function fails to meet the postcondition, `terminate`
|
| 69 |
+
is called [[except.terminate]].
|
| 70 |
+
|
| 71 |
+
[*Note 5*: This can happen if the re-locking of the mutex throws an
|
| 72 |
+
exception. — *end note*]
|
| 73 |
+
|
| 74 |
+
*Throws:* Timeout-related exceptions [[thread.req.timing]], or any
|
| 75 |
+
exception thrown by `pred`.
|
| 76 |
+
|
| 77 |
+
``` cpp
|
| 78 |
+
template<class Lock, class Rep, class Period, class Predicate>
|
| 79 |
+
bool wait_for(Lock& lock, stop_token stoken,
|
| 80 |
+
const chrono::duration<Rep, Period>& rel_time, Predicate pred);
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
*Effects:* Equivalent to:
|
| 84 |
+
|
| 85 |
+
``` cpp
|
| 86 |
+
return wait_until(lock, std::move(stoken), chrono::steady_clock::now() + rel_time,
|
| 87 |
+
std::move(pred));
|
| 88 |
+
```
|
| 89 |
+
|