Condition variable class. More...
#include <tinythread.h>
Public Member Functions | |
| condition_variable () | |
| Constructor. | |
| ~condition_variable () | |
| Destructor. | |
| template<class _mutexT > | |
| void | wait (_mutexT &aMutex) |
| Wait for the condition. | |
| void | notify_one () |
| Notify one thread that is waiting for the condition. | |
| void | notify_all () |
| Notify all threads that are waiting for the condition. | |
Condition variable class.
This is a signalling object for synchronizing the execution flow for several threads. Example usage:
// Shared data and associated mutex and condition variable objects int count; mutex m; condition_variable cond; // Wait for the counter to reach a certain number void wait_counter(int targetCount) { lock_guard<mutex> guard(m); while(count < targetCount) cond.wait(m); } // Increment the counter, and notify waiting threads void increment() { lock_guard<mutex> guard(m); ++ count; cond.notify_all(); }
| void notify_all | ( | ) | [inline] |
Notify all threads that are waiting for the condition.
All threads that are blocked waiting for this condition variable will be woken up.
| void notify_one | ( | ) | [inline] |
Notify one thread that is waiting for the condition.
If at least one thread is blocked waiting for this condition variable, one will be woken up.
| void wait | ( | _mutexT & | aMutex | ) | [inline] |
Wait for the condition.
The function will block the calling thread until the condition variable is woken by notify_one(), notify_all() or a spurious wake up.
| [in] | aMutex | A mutex that will be unlocked when the wait operation starts, an locked again as soon as the wait operation is finished. |
1.6.3