Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNts_condition_c Class Reference

#include <CAVERNts_condition_c.hxx>

List of all members.

Public Methods

int wait (CAVERNts_mutex_c *mutex)
int signal ()
int broadcastSignal ()
CAVERN_COND_T* getCondition ()
 Return condition variable.

 CAVERNts_condition_c ()
 ~CAVERNts_condition_c ()

Private Attributes

CAVERN_COND_T itsCV


Detailed Description

Class for thread condition variables. Condition variables are used in conjunction with mutexes to provide a way for threads to wait until a condition occurs.

An example of waiting on a signal is:

\begin{verbatim}

Lock your mutex that is protecting someState. myMutex->lock();

Watch for your desired state to occur. while(someState != reached) {

Wait for a signal. myCondition->wait(myMutex);

.... got the condition and the lock so now continue ....

}

myMutex->unlock();

\end{verbatim}

An example of sending the signal is:

\begin{verbatim}

Lock your mutex that is protecting someState. myMutex->lock();

Signal that the state has been reached. if (someState == reached) myCondition->signal();

Unlock your mutex so that the waiting thread can continue. myMutex->unlock();

\end{verbatim}


Member Function Documentation

int CAVERNts_condition_c::broadcastSignal ( )
 

Signal that a condition has arisen. This wakes up ALL threads that are suspended on this condition. If no threads are suspended this call has no effect.

Returns:
0 if function successfully completes else non-zero

int CAVERNts_condition_c::signal ( )
 

Signal that a condition has arisen. This wakes up one thread that is suspended on this condition. If no threads are suspended this call has no effect.

Returns:
0 if function successfully completes else non-zero

int CAVERNts_condition_c::wait ( CAVERNts_mutex_c * mutex )
 

Wait on a condition to be signalled. This function first releases the mutex and then waits on the condition. When the condition arises (ie it has been signaled) the mutex is reaquired, and the function returns.

Returns:
0 if function successfully completes else non-zero


The documentation for this class was generated from the following file:
Generated at Mon Jul 2 14:24:45 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001