[thread.condition.condvarany] (original) (raw)
[Note 1:
All of the standard mutex types meet this requirement.
If a type other than one of the standard mutex types or a unique_lock wrapper for a standard mutex type is used with condition_variable_any, any necessary synchronization is assumed to be in place with respect to the predicate associated with the condition_variable_any instance.
— _end note_]
namespace std { class condition_variable_any { public: condition_variable_any();~condition_variable_any(); condition_variable_any(const condition_variable_any&) = delete; condition_variable_any& operator=(const condition_variable_any&) = delete;void notify_one() noexcept;void notify_all() noexcept;template<class Lock> void wait(Lock& lock);template<class Lock, class Predicate> void wait(Lock& lock, Predicate pred);template<class Lock, class Clock, class Duration> cv_status wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time);template<class Lock, class Clock, class Duration, class Predicate> bool wait_until(Lock& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);template<class Lock, class Rep, class Period> cv_status wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time);template<class Lock, class Rep, class Period, class Predicate> bool wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred);template<class Lock, class Predicate> bool wait(Lock& lock, stop_token stoken, Predicate pred);template<class Lock, class Clock, class Duration, class Predicate> bool wait_until(Lock& lock, stop_token stoken,const chrono::time_point<Clock, Duration>& abs_time, Predicate pred);template<class Lock, class Rep, class Period, class Predicate> bool wait_for(Lock& lock, stop_token stoken,const chrono::duration<Rep, Period>& rel_time, Predicate pred);};}
Preconditions: There is no thread blocked on *this.
[Note 2:
That is, all threads have been notified; they can subsequently block on the lock specified in the wait.
This relaxes the usual rules, which would have required all wait calls to happen before destruction.
Only the notification to unblock the wait needs to happen before destruction.
Undefined behavior ensues if a thread waits on *this once the destructor has been started, especially when the waiting threads are calling the wait functions in a loop or using the overloads of wait, wait_for, or wait_until that take a predicate.
— _end note_]
Effects: If any threads are blocked waiting for *this, unblocks one of those threads.
Effects: Unblocks all threads that are blocked waiting for *this.