ASL
Condition Class Reference

Detailed Description

A condition variable allows one or more threads to wait until a condition is made true by another thread.

The condition or watched resource itself must be protected by a mutex and this mutex given to the condition variable. This is how this is done:

We have the ready flag to wait until it is true:

bool ready = false;
Mutex mutex;
Condition condition(mutex);

One thread waits for it to become true like this:

mutex.lock();
while (!ready)
condition.wait();
mutex.unlock();

Another thread, when it is ready signals it like this:

mutex.lock();
ready = true;
condition.signal();
mutex.unlock();

#include <Mutex.h>

Public Member Functions

 Condition (Mutex &m)
 Constructs a condition variable with a mutex to use.
 
void use (Mutex &m)
 Sets mutex to use if it was not given in the constructor.
 
void signal ()
 Wake up waiting threads to signal a condition change.
 
void wait ()
 Wait for the condition change to be signaled.
 
bool wait (double timeout)
 Wait for the condition change to be signaled up to a timeout and return true if there was no signal.
 

The documentation for this class was generated from the following file: