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 tobool.Lockablemeets theLockableRequirements, andlockowns a lock.- Effects:
-
As-if
while(!pred()) { wait(lock); }
- Throws:
Any exception thrown by a call to
pred, orstd::system_errorif the effects could not be achieved.- 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()returnstrue.- Synchronization:
Calls to
notify_one(),notify_all(),wait(),wait_for()andwait_until()on a singlestd::condition_variable_anyinstance are serialized. A call tonotify_one()ornotify_all()will only wake threads that started waiting prior to that call.
Header
#include <condition_variable>