class CAVERNplus_condition_c

Class for thread condition variables

Public Methods

int broadcastSignal ()
Signal that a condition has arisen
nexus_cond_t* getNexusCondition ()
Return nexus' condition variable.
int signal ()
Signal that a condition has arisen
int wait (CAVERNplus_mutex_c *mutex)
Wait on a condition to be signalled

Documentation

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:


// 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();

An example of sending the signal is:


// 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();

int wait(CAVERNplus_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

int 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 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


This class has no child classes.

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de