std::condition_variable_any

From cppreference.com
< cpp‎ | thread
 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
condition_variable_any
(C++11)
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
 
 
Defined in header <condition_variable>
class condition_variable_any;
(since C++11)

The condition_variable_any class is a generalization of std::condition_variable. Whereas std::condition_variable works only on std::unique_lock<std::mutex>, condition_variable_any can operate on any lock that meets the BasicLockable requirements.

See std::condition_variable for the description of the semantics of condition variables.

The class std::condition_variable_any is a standard-layout class. It is not copy-constructible, move-constructible, copy-assignable, or move-assignable.

If the lock is std::unique_lock, std::condition_variable may provide better performance.

Member functions

constructs the object
(public member function)
destructs the object
(public member function)
operator=
[deleted]
not copy-assignable
(public member function)
Notification
notifies one waiting thread
(public member function)
notifies all waiting threads
(public member function)
Waiting
blocks the current thread until the condition variable is woken up
(public member function)
blocks the current thread until the condition variable is woken up or after the specified timeout duration
(public member function)
blocks the current thread until the condition variable is woken up or until specified time point has been reached
(public member function)

Notes

std::condition_variable_any can be used with std::shared_lock in order to wait on a std::shared_mutex in shared ownership mode.

A possible use for std::condition_variable_any with custom Lockable types is to provide convenient interruptible waits: the custom lock operation would both lock the associated mutex as expected, and also perform the necessary setup to notify this condition variable when the interrupting signal is received.[1]

References

  1. A. Williams (2012), "C++ concurrency in action" 9.2.4 Interupting a wait on std::condition_variable_any