Wait until the std::condition_variable_any
is woken
by a call to notify_one()
or notify_all()
,
and the predicate is true
,
or until the specified time has been reached.
template<typename Lockable,typename Clock, typename Duration, typename Predicate> bool wait_until( Lockable& lock, std::chrono::time_point<Clock,Duration> const& absolute_time, Predicate pred);
The expression pred()
shall be valid, and shall return
a value that is convertible to bool
.
Lockable
meets
the Lockable
Requirements, and lock
owns a lock.
As-if
while(!pred()) { if(wait_until(lock,absolute_time)== std::cv_status::timeout) return pred(); } return true;
true
if the most recent
call to pred()
returned true
, false
if a call to Clock::now()
returned a time equal to or later than the time specified by absolute_time
, and pred()
returned false
.
The potential for spurious wake ups means that it is unspecified
how many times pred
will be called. pred
will always be invoked with the mutex referenced by lock
locked, and the function
shall return if (and only if) an evaluation of (bool)pred()
returns true
or Clock::now()
returns a time equal to or later than absolute_time
.
There is no guarantee as to how long the calling thread will be
blocked for, only that if the function returns false
then Clock::now()
returned a time equal to or later than absolute_time
at the point at which the thread became unblocked.
Any exception thrown by a call to pred
,
or std::system_error
if the effects
could not be achieved.
Calls to notify_one()
,
notify_all()
,
wait()
,
wait_until()
and wait_until()
on a single std::condition_variable_any
instance are serialized. A call to notify_one()
or notify_all()
will only wake threads that started waiting prior
to that call.
#include <condition_variable>