Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::ConditionVariable Class Reference
[Threading API]

#include <ConditionVariable.h>

List of all members.

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.


Detailed Description

A class for a conditional variable. This is to be used when a thread needs to wait for a condition that another thread will trigger. The most common usage of ConditionVariables:

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

GNE::ConditionVariable::ConditionVariable Mutex m  ) 
 

Initalizes this class, with another mutex that the caller is responsible for allocating and destroying.

Parameters:
m the mutex to be associated with this conditional variable. this mutex will not be deallocated.


Member Function Documentation

void GNE::ConditionVariable::acquire  ) 
 

Locks the associated mutex for this condition variable.

See also:
Mutex::acquire()

void GNE::ConditionVariable::release  ) 
 

Releases the associated mutex.

See also:
Mutex::release()

void GNE::ConditionVariable::signal  ) 
 

Wakes up at least one thread waiting on this CV.

Which thread wakes up is implementation dependant.

void GNE::ConditionVariable::timedWait int  ms  ) 
 

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.

Parameters:
timeout the time to wait in milliseconds

void GNE::ConditionVariable::wait  ) 
 

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.


The documentation for this class was generated from the following files:
Generated on Fri Aug 22 13:40:06 2003 for GNE by doxygen1.3