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

Wait until the std::condition_variable_any is woken by a call to notify_one() or notify_all(), and the predicate is true.

template<typename Lockable,typename Predicate>
void wait(Lockable& lock,Predicate pred);

Preconditions:

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.

Effects:

As-if

while(!pred())
{
    wait(lock);
}
Throws:

Any exception thrown by a call to pred, or std::system_error if the effects could not be achieved.

Note:

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.

Synchronization:

Calls to notify_one(), notify_all(), wait(), wait_for() 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.

Header

#include <condition_variable>

See Also