A class used to block a thread until a condition is met, as signaled by a different thread.
This class is used to perform synchronization between threads. The typical usage is that one or more threads 'wait' on the condition, and a different thread signals one or more of the waiters to wake up.
When waiting on a wait conditions, threads are expected to have a mutex locked. When a thread 'waits' on a wait condition, the mutex is unlocked automatically, and re-locked when a different thread calls 'wake' (or when a timeout is reached).
Sample usage:
Thread 1 (consumer):
Thread 2 (producer):
#include <thread/YiWaitCondition.h>
Public Member Functions | |
| CYIWaitCondition () | |
| virtual | ~CYIWaitCondition () |
| bool | Wait (CYIMutex &rMutex) |
| bool | Wait (CYIMutex &rMutex, uint64_t timeoutMs) |
| bool | WakeAll () |
| bool | WakeOne () |
| CYIWaitCondition::CYIWaitCondition | ( | ) |
|
virtual |
| bool CYIWaitCondition::Wait | ( | CYIMutex & | rMutex | ) |
Waits on this condition until a different thread calls WakeOne or WakeAll.
The mutex rMutex must be locked by the current thread prior to this function. While waiting, the mutex will be automatically unlocked, and will be re-locked when this function returns.
| bool CYIWaitCondition::Wait | ( | CYIMutex & | rMutex, |
| uint64_t | timeoutMs | ||
| ) |
Waits on this condition until a different thread calls WakeOne or WakeAll, or until timeoutMs milliseconds have elapsed.
The mutex rMutex must be locked by the current thread prior to this function. While waiting, the mutex will be automatically unlocked, and will be re-locked when this function returns.
| bool CYIWaitCondition::WakeAll | ( | ) |
Causes all threads waiting on this condition to be awoken. Has no effect if no threads are currently waiting on this wait condition.
| bool CYIWaitCondition::WakeOne | ( | ) |
Causes a single thread waiting on this condition to be awoken. There is no specified ordering to which thread is selected to be awoken. Has no effect if no threads are currently waiting on this wait condition.