Documentation Home >> Headers >> <condition_variable> Header >> std::condition_variable >> std::condition_variable::wait_until Member function overload that takes a predicate

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&
    Predicate pred);


The expression pred() shall be valid, and shall return a value that is convertible to bool. lock.owns_lock() shall be true, and the lock shall be owned by the thread calling wait().



        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 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>

See Also