#include <ConditionVariable.h>
Public Member Functions | |
ConditionVariable () | |
Initalizes this class creating a new mutex. | |
ConditionVariable (Mutex *m) | |
Initalizes this class, with another mutex that the caller is responsible for allocating and destroying. | |
void | acquire () |
Locks the associated mutex for this condition variable. | |
void | release () |
Releases the associated mutex. | |
void | wait () |
This method will block until the thread is woken up by a call to signal or broadcast. | |
void | timedWait (int ms) |
This method works identical to wait, except the thread will wake up anyways if not woken up before the timeout. | |
void | timedWait (const Time &until) |
Waits until the given time, specified in absolute time. | |
void | signal () |
Wakes up at least one thread waiting on this CV. | |
void | broadcast () |
Wakes up all threads waiting on this CV. |
cv.lock(); while (!condition) { cv.wait(); } //do stuff cv.unlock();When cv.wait is called, the thread atomically releases the associated mutex and waits for another thread to call signal or broadcast on the cv object. When this thread reawakens, it waits to lock the associated mutex then exits the wait call.
Constructor & Destructor Documentation
|
Initalizes this class, with another mutex that the caller is responsible for allocating and destroying.
|
|
Locks the associated mutex for this condition variable.
|
|
Releases the associated mutex.
|
|
Wakes up at least one thread waiting on this CV. Which thread wakes up is implementation dependant. |
|
This method works identical to wait, except the thread will wake up anyways if not woken up before the timeout. The mutex will still be reacquired.
|
|
This method will block until the thread is woken up by a call to signal or broadcast. The associated mutex must be locked when wait() is called. wait() will unlock the mutex and block until woken up at which point it will re-acquire the mutex. |