Init
This commit is contained in:
138
cppdraft/thread/condvarany/intwait.md
Normal file
138
cppdraft/thread/condvarany/intwait.md
Normal file
@@ -0,0 +1,138 @@
|
||||
[thread.condvarany.intwait]
|
||||
|
||||
# 32 Concurrency support library [[thread]](./#thread)
|
||||
|
||||
## 32.7 Condition variables [[thread.condition]](thread.condition#thread.condvarany.intwait)
|
||||
|
||||
### 32.7.5 Class condition_variable_any [[thread.condition.condvarany]](thread.condition.condvarany#thread.condvarany.intwait)
|
||||
|
||||
#### 32.7.5.3 Interruptible waits [thread.condvarany.intwait]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10313)
|
||||
|
||||
The following wait functions will be notified
|
||||
when there is a stop request on the passed stop_token[.](#1.sentence-1)
|
||||
|
||||
In that case the functions return immediately,
|
||||
returning false if the predicate evaluates to false[.](#1.sentence-2)
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`template<class Lock, class Predicate>
|
||||
bool wait(Lock& lock, stop_token stoken, Predicate pred);
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10325)
|
||||
|
||||
*Effects*: Registers for the duration of this call *this to get notified on a stop request on stoken during this call and then equivalent to:while (!stoken.stop_requested()) {if (pred())return true;
|
||||
wait(lock);}return pred();
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10339)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The returned value indicates whether the predicate evaluated totrue regardless of whether there was a stop request[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10345)
|
||||
|
||||
*Postconditions*: lock is locked by the calling thread[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10349)
|
||||
|
||||
*Throws*: Any exception thrown by pred[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10353)
|
||||
|
||||
*Remarks*: If the function fails to meet the postcondition,terminate is called ([[except.terminate]](except.terminate "14.6.2 The std::terminate function"))[.](#6.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
This can happen if the re-locking of the mutex throws an exception[.](#6.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`template<class Lock, class Clock, class Duration, class Predicate>
|
||||
bool wait_until(Lock& lock, stop_token stoken,
|
||||
const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10369)
|
||||
|
||||
*Effects*: Registers for the duration of this call *this to get notified on a stop request on stoken during this call and then equivalent to:while (!stoken.stop_requested()) {if (pred())return true; if (wait_until(lock, abs_time) == cv_status::timeout)return pred();}return pred();
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10384)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
There is no blocking if pred() is initially true,stoken.stop_requested() was already true or the timeout has already expired[.](#8.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10391)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
The returned value indicates whether the predicate evaluated to true regardless of whether the timeout was triggered or a stop request was made[.](#9.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10397)
|
||||
|
||||
*Postconditions*: lock is locked by the calling thread[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10401)
|
||||
|
||||
*Throws*: Timeout-related exceptions ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications")),
|
||||
or any exception thrown by pred[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10406)
|
||||
|
||||
*Remarks*: If the function fails to meet the postcondition,terminate is called ([[except.terminate]](except.terminate "14.6.2 The std::terminate function"))[.](#12.sentence-1)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
This can happen if the re-locking of the mutex throws an exception[.](#12.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`template<class Lock, class Rep, class Period, class Predicate>
|
||||
bool wait_for(Lock& lock, stop_token stoken,
|
||||
const chrono::duration<Rep, Period>& rel_time, Predicate pred);
|
||||
`
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10422)
|
||||
|
||||
*Effects*: Equivalent to:return wait_until(lock, std::move(stoken), chrono::steady_clock::now() + rel_time,
|
||||
std::move(pred));
|
||||
223
cppdraft/thread/condvarany/wait.md
Normal file
223
cppdraft/thread/condvarany/wait.md
Normal file
@@ -0,0 +1,223 @@
|
||||
[thread.condvarany.wait]
|
||||
|
||||
# 32 Concurrency support library [[thread]](./#thread)
|
||||
|
||||
## 32.7 Condition variables [[thread.condition]](thread.condition#thread.condvarany.wait)
|
||||
|
||||
### 32.7.5 Class condition_variable_any [[thread.condition.condvarany]](thread.condition.condvarany#thread.condvarany.wait)
|
||||
|
||||
#### 32.7.5.2 Noninterruptible waits [thread.condvarany.wait]
|
||||
|
||||
[ð](#lib:wait,condition_variable_any)
|
||||
|
||||
`template<class Lock>
|
||||
void wait(Lock& lock);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10135)
|
||||
|
||||
*Effects*:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
Atomically calls lock.unlock() and blocks on *this[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
When unblocked, calls lock.lock() (possibly blocking on the lock) and returns[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
The function will unblock when signaled by a call to notify_one(),
|
||||
a call to notify_all(), or spuriously[.](#1.3.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10145)
|
||||
|
||||
*Postconditions*: lock is locked by the calling thread[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10149)
|
||||
|
||||
*Throws*: Nothing[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10153)
|
||||
|
||||
*Remarks*: If the function fails to meet the postcondition, terminate() is invoked ([[except.terminate]](except.terminate "14.6.2 The std::terminate function"))[.](#4.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This can happen if the re-locking of the mutex throws an exception[.](#4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:wait,condition_variable_any_)
|
||||
|
||||
`template<class Lock, class Predicate>
|
||||
void wait(Lock& lock, Predicate pred);
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10169)
|
||||
|
||||
*Effects*: Equivalent to:while (!pred()) wait(lock);
|
||||
|
||||
[ð](#lib:wait_until,condition_variable_any)
|
||||
|
||||
`template<class Lock, class Clock, class Duration>
|
||||
cv_status wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time);
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10185)
|
||||
|
||||
*Effects*:
|
||||
|
||||
- [(6.1)](#6.1)
|
||||
|
||||
Atomically calls lock.unlock() and blocks on *this[.](#6.1.sentence-1)
|
||||
|
||||
- [(6.2)](#6.2)
|
||||
|
||||
When unblocked, calls lock.lock() (possibly blocking on the lock) and returns[.](#6.2.sentence-1)
|
||||
|
||||
- [(6.3)](#6.3)
|
||||
|
||||
The function will unblock when signaled by a call to notify_one(), a call to notify_all(),
|
||||
expiration of the absolute timeout ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications")) specified by abs_time,
|
||||
or spuriously[.](#6.3.sentence-1)
|
||||
|
||||
- [(6.4)](#6.4)
|
||||
|
||||
If the function exits via an exception, lock.lock() is called prior to exiting the function[.](#6.4.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10204)
|
||||
|
||||
*Postconditions*: lock is locked by the calling thread[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10208)
|
||||
|
||||
*Returns*: cv_status::timeout if
|
||||
the absolute timeout ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications")) specified by abs_time expired,
|
||||
otherwise cv_status::no_timeout[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10214)
|
||||
|
||||
*Throws*: Timeout-related
|
||||
exceptions ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications"))[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10219)
|
||||
|
||||
*Remarks*: If the function fails to meet the postcondition, terminate() is invoked ([[except.terminate]](except.terminate "14.6.2 The std::terminate function"))[.](#10.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
This can happen if the re-locking of the mutex throws an exception[.](#10.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:wait_for,condition_variable_any)
|
||||
|
||||
`template<class Lock, class Rep, class Period>
|
||||
cv_status wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);
|
||||
`
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10235)
|
||||
|
||||
*Effects*: Equivalent to:return wait_until(lock, chrono::steady_clock::now() + rel_time);
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10242)
|
||||
|
||||
*Postconditions*: lock is locked by the calling thread[.](#12.sentence-1)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10246)
|
||||
|
||||
*Returns*: cv_status::timeout if
|
||||
the relative timeout ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications")) specified by rel_time expired,
|
||||
otherwise cv_status::no_timeout[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10252)
|
||||
|
||||
*Throws*: Timeout-related
|
||||
exceptions ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications"))[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10257)
|
||||
|
||||
*Remarks*: If the function fails to meet the postcondition, terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std::terminate function"))[.](#15.sentence-1)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
This can happen if the re-locking of the mutex throws an exception[.](#15.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:wait_until,condition_variable_any_)
|
||||
|
||||
`template<class Lock, class Clock, class Duration, class Predicate>
|
||||
bool wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);
|
||||
`
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10273)
|
||||
|
||||
*Effects*: Equivalent to:while (!pred())if (wait_until(lock, abs_time) == cv_status::timeout)return pred();return true;
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10283)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
There is no blocking if pred() is initially true, or
|
||||
if the timeout has already expired[.](#17.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10289)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
The returned value indicates whether the predicate evaluates to true regardless of whether the timeout was triggered[.](#18.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:wait_for,condition_variable_any_)
|
||||
|
||||
`template<class Lock, class Rep, class Period, class Predicate>
|
||||
bool wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred);
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10303)
|
||||
|
||||
*Effects*: Equivalent to:return wait_until(lock, chrono::steady_clock::now() + rel_time, std::move(pred));
|
||||
Reference in New Issue
Block a user