Main Page   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members  

Condition Class Reference

#include <Condition.h>

Inheritance diagram for Condition:

Waitable NonCopyable List of all members.

Public Methods

 Condition (Lockable &l)
 ~Condition () throw ()
 Destroy Condition object.

void signal ()
void broadcast ()
virtual void wait ()
virtual bool wait (unsigned long timeout)

Detailed Description

Author:
Eric Crahen <crahen@cse.buffalo.edu>
Date:
<2002-06-02T08:10:20-0400>
Version:
2.2.1
A Condition is a Waitable object used to block a thread until a particular condition is met. A Condition object is always used in conjunction with Lockable object. This object should be a FastMutex, Mutex, PriorityMutex or PriorityInheritanceMutex.

Condition objects are reminicent of POSIX condition variables in several ways but are slightly different.

A Condition is not subject to spurious wakeup.

Like all Waitable objects, Conditions are sensative to Thread::interupt() which can be used to prematurely end a wait().

See also:
Thread::interupt()
Before a wait() is performed on a Condition, the associated Lockable object should have been acquire()ed. When the wait() begins, that Lockable object is release()d (wait() will atomically begin the wait and unlock the Lockable).

A thread blocked by wait() will remain so until an exception occurs, or until the thread awakened by a signal() or broadcast(). When the thread resumes execution, the associated Lockable is acquire()d before wait() returns.

Scheduling

Threads blocked on a Condition are resumed in FIFO order.


Constructor & Destructor Documentation

Condition Lockable   l
 

Create a new condition variable associated with the given Lockable object.

Parameters:
l  - Lockable object to associate with this Condition object.
Exceptions:
Synchronization_Exception  thrown if there is some error creating the Condition object


Member Function Documentation

void broadcast  
 

Wake ALL threads wait()ing on this Condition.

Postcondition:
all wait()ing threads, if any exist, will be awakened.
Exceptions:
Synchronization_Exception  thrown if there is an error performing this operation

void signal  
 

Wake ONE threads wait()ing on this Condition.

Postcondition:
a wait()ing thread, if any exists, will be awakened.
Exceptions:
Synchronization_Exception  thrown if there is an error performing this operation

virtual bool wait unsigned long    timeout [virtual]
 

Wait for this Condition object to be signal()ed. The thread calling this method will block until the Condition is signal()ed, broadcast() to or until the timeout expires.

This operation atomically release()s the associated Lockable and blocks the calling thread.

Parameters:
timeout  - maximum amount of time (milliseconds) this method could block
Returns :
true if the Condition was signal()ed before the timeout expired, otherwise false.
Exceptions:
Interrupted_Exception  thrown when the calling thread is interupt()ed. A thread may be interrupted at any time, prematurely ending any wait.
Precondition:
The thread calling this method must have first acquire()d the associated Lockable object.
Postcondition:
A thread that has resumed execution without exception (because of a signal(), broadcast() or exception) will have acquire()d the associated Lockable object before returning from a wait().
See also:
Waitable::wait(timeout)

Reimplemented from Waitable.

virtual void wait   [virtual]
 

Wait for this Condition object to be signal()ed. The thread calling this method will block until the Condition is signal()ed or broadcast() to.

This operation atomically release()s the associated Lockable and blocks the calling thread.

Exceptions:
Interrupted_Exception  thrown when the calling thread is interupt()ed. A thread may be interrupted at any time, prematurely ending any wait.
Precondition:
The thread calling this method must have first acquire()d the associated Lockable object.
Postcondition:
A thread that has resumed execution without exception (because of a signal(), broadcast() or exception) will have acquire()d the associated Lockable object before returning from a wait().
See also:
Waitable::wait()

Reimplemented from Waitable.


The documentation for this class was generated from the following file:
Generated on Tue Aug 27 07:43:11 2002 for ZThread by doxygen1.2.17