The Micro C++ Library
micxx::Condition Class Reference

A Condition provides yet another way for threads to synchronize based upon the actual value of data. More...

#include <micxx.hxx>

Inherits micxx::Mutex.

Inherited by micxx::PCQueue< T >, and micxx::Semaphore [protected].

List of all members.

Public Member Functions

 Condition ()
 Create a new Condition.
virtual ~Condition ()
 Deallocate and release the internally allocated condition resources.
virtual bool wait (unsigned long timeoutMillis=0)
 Blocks the calling thread until it is signaled from any other thread by notifyAll().
virtual void notifyAll ()
 Signals all waiting threads that the Condition is met.

Detailed Description

A Condition provides yet another way for threads to synchronize based upon the actual value of data.

"Without condition variables, the programmer would need to have threads continually polling (possibly in a critical section), to check if the condition is met. This can be very resource consuming since the thread would be continuously busy in this activity. A condition variable is a way to achieve the same goal without polling."

A condition variable must always be used in conjunction with a mutex lock.

Author:
Norbert Klose
Date:
June, 2007

Constructor & Destructor Documentation

micxx::Condition::Condition ( )

Create a new Condition.

virtual micxx::Condition::~Condition ( ) [virtual]

Deallocate and release the internally allocated condition resources.


Member Function Documentation

virtual void micxx::Condition::notifyAll ( ) [virtual]

Signals all waiting threads that the Condition is met.

All threads waiting for this Condition to be met continue its execution, competing for the lock of the underlying mutex again in order to return from wait().

Note:
The calling thread must have obtained the lock of the underlying mutex before notifyAll() could be called. The calling thread does not release the lock of the underlying mutex automatically, instead it must not forget to call unlock() afterwards.
virtual bool micxx::Condition::wait ( unsigned long  timeoutMillis = 0) [virtual]

Blocks the calling thread until it is signaled from any other thread by notifyAll().

As long as wait() does not return any other thread may be able to obtain the lock of the underlying mutex.

Parameters:
timeoutMillisThe number of milli seconds to wait until the call returns without being signaled by notifyAll().
If 0, the call will wait indefinitely long.
Note:
The calling thread must have obtained the lock of the underlying mutex before wait() could be called. As soon as wait() returns, the calling thread again is the owner of the lock of the underlying mutex and must not forget to call unlock() afterwards.

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