cpp/thread/condition variable

The class is a synchronization primitive used with a std to block one or more threads until another thread both modifies a shared variable (the condition) and notifies the.

The thread that intends to modify the shared variable must: Even if the shared variable is atomic, it must be modified while owning the mutex to correctly publish the modification to the waiting thread.
 * 1) Acquire a  (typically via std)
 * 2) Modify the shared variable while the lock is owned
 * 3) Call notify_one or notify_all on the  (can be done after releasing the lock)

Any thread that intends to wait on a must:
 * 1) Acquire a  on the mutex used to protect the shared variable
 * 2) Do one of the following:
 * Check the condition, in case it was already updated and notified
 * Call wait, wait_for, or wait_until on the (atomically releases the mutex and suspends thread execution until the condition variable is notified, a timeout expires, or a spurious wakeup occurs, then atomically acquires the mutex before returning)
 * Check the condition and resume waiting if not satisfied
 * or:
 * Use the predicated overload of wait, wait_for, and wait_until, which performs the same three steps

works only with, which allows for maximal efficiency on some platforms. std provides a condition variable that works with any object, such as  std.

Condition variables permit concurrent invocation of the wait, wait_for, wait_until, notify_one and notify_all member functions.

The class is a. It is not, , , or.