Wait until the std::condition_variable 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 Clock,typename Duration, typename Predicate> bool wait_until(std::unique_lock<std::mutex>& lock, std::chrono::time_point<Clock,Duration> const& absolute_time); Predicate pred);
- Preconditions:
The expression
pred()shall be valid, and shall return a value that is convertible tobool.lock.owns_lock()shall betrue, and the lock shall be owned by the thread callingwait().- Effects:
-
As-if
while(!pred()) { if(wait_until(lock,absolute_time)==std::cv_status::timeout) return pred(); } return true;
- Returns:
trueif the most recent call topred()returnedtrue,falseif a call toClock::now()returned a time equal to or later than the time specified byabsolute_time, andpred()returnedfalse.- Note:
The potential for spurious wake ups means that it is unspecified how many times
predwill be called.predwill always be invoked with the mutex referenced bylocklocked, and the function shall return if (and only if) an evaluation of(bool)pred()returnstrueorClock::now()returns a time equal to or later thanabsolute_time. There is no guarantee as to how long the calling thread will be blocked for, only that if the function returnsfalsethenClock::now()returned a time equal to or later thanabsolute_timeat the point at which the thread became unblocked.- Throws:
Any exception thrown by a call to
pred, orstd::system_errorif the effects could not be achieved.- Synchronization:
Calls to
notify_one(),notify_all(),wait(),wait_until()andwait_until()on a singlestd::condition_variableinstance are serialized. A call tonotify_one()ornotify_all()will only wake threads that started waiting prior to that call.
Header
#include <condition_variable>