public member function
<condition_variable>
std::condition_variable::wait_until unconditional (1)template <class Clock, class Duration> cv_status wait_until (unique_lock<mutex>& lck, const chrono::time_point<Clock,Duration>& abs_time);predicate (2)
template <class Clock, class Duration, class Predicate> bool wait_until (unique_lock<mutex>& lck, const chrono::time_point<Clock,Duration>& abs_time, Predicate pred);
Wait until notified or time point
The execution of the current thread (which shall have locked lck's mutex) is blocked either until notified or until abs_time, whichever happens first.At the moment of blocking the thread, the function automatically calls lck.unlock()
, allowing other locked threads to continue.
Once notified or once it is abs_time, the function unblocks and calls lck.lock()
, leaving lck in the same state as when the function was called. Then the function returns (notice that this last mutex locking may block again the thread before returning).
Generally, the function is notified to wake up by a call in another thread either to member notify_one or to member notify_all. But certain implementations may produce spurious wake-up calls without any of these functions being called. Therefore, users of this function shall ensure their condition for resumption is met.
If pred is specified (2), the function only blocks if pred returns false
, and notifications can only unblock the thread when it becomes true
(which is especially useful to check against spurious wake-up calls). It behaves as if implemented as:
1
2
3
4
while (!pred())
if ( wait_until(lck,abs_time) == cv_status::timeout)
return pred();
return true;
lck.mutex()
).
bool
.
true
.
pred()
, regardless of whether the timeout was triggered (although it can only be false
if triggered).
Otherwise, if an exception is thrown, both the condition_variable
object and the arguments are in a valid state (basic guarantee).
It may throw
system_errorin case of failure (transmitting any error condition from the respective call to
lockor
unlock).
The predicate version (2) may also throw any exception thrown by pred.
On exception, the state of lck is attempted to be restored before exiting the function scope (by calling lck.lock()
).
It may throw if an operation related to
abs_timethrows (note that operations on the standard
clockand
durationtypes provided in
<chrono>
never throw).
The predicate version (2) may also throw exceptions thrown by pred.
If the function is not able to restore the lock and return at some point (such as if some attempt to lock or unlock throws), std::terminate is called.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4