Namespaces
Variants
Views
Actions

std::condition_variable_any

From cppreference.com
< cpp‎ | thread
Revision as of 20:19, 2 November 2012 by P12bot (Talk | contribs)

 
 
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 user-defined lock that meets the BasicLockable requirements.

condition_variable_any provides similar functionality to std::condition_variable. It is a synchronization primitive that can be used to block some number of threads until:

  • a notification is received from another thread
  • a timeout expires, or
  • a spurious wakeup occurs

Any thread that intends to wait on std::condition_variable_any has to acquire a lock first. The wait operations atomically release the lock and suspend the execution of the thread. When the condition variable is notified, the thread is awakened, and the lock is reacquired.

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

Template:cpp/thread/condition variable/dcl list constructorTemplate:cpp/thread/condition variable/dcl list destructorTemplate:cpp/thread/condition variable/dcl list operator=Template:cpp/thread/condition variable/dcl list notify oneTemplate:cpp/thread/condition variable/dcl list notify allTemplate:cpp/thread/condition variable/dcl list waitTemplate:cpp/thread/condition variable/dcl list wait forTemplate:cpp/thread/condition variable/dcl list wait until
Notification
Waiting