ICondition

ICondition is the abstract base class for all condition classes. Conditions are used in two ways. They can provide monitor/condition style services and they can provide traditional event semaphore services.

Threads can wait on conditions (using the wait() method), and other threads can signal or broadcast the condition to let waiting threads continue execution. This is the standard event semaphore paradigm. The condition represents an 'auto mode' event, that either lets one waiting thread go (signal) or lets all waiting threads go (broadcast.) Once the signal or broadcast completes, it resets itself automatically (as apposed to a manual mode event that stays triggered until it is manually reset.)

To also support monitor/condition type of services, there is an alternative form of the wait() method that takes a resource lock. While the thread is in the condition wait, the resource lock is unlocked. This lets multiple threads fight over a single resource while simultaneously being blocked periodically on a condition. The resource object that is locked by the passed resource lock is unwound as many times as necessary to unlock the resource. When the thread wakes up from the condition wait then it will continue to block until it can regain the resource lock. Once regained, the resource is wound back up as many times as it previously was locked. Since all recursive locks must occur on the same thread, this is safe.


ICondition - Member Functions and Data by Group

Constructors & Destructor

Construct and destruct ICondition objects.


[view class]
~ICondition
public:
virtual ~ICondition()
The destructor has nothing to do at this level and is just an empty inline implementation.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
ICondition
protected:
ICondition()
ICondition constructors are not publically available since it is an abstract base class. The constructors that are implemented are only available to derived classes or friends.
The default constructor is hidden and only available to derived classes, since ICondition is an abstract base class.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Synchronization Methods

These methods define the synchronization interface for conditions.


[view class]
broadcast
Derived class should release all waiting threads.
public:
virtual void broadcast() = 0
Allows all threads, currently waiting on this condition, to return from their wait operations. In some platform implementations, threads entering wait() while the broadcast is being done might also be allowed to pass on through, i.e. it does not necessarily take a snapshot of waiting threads. Once there are no more threads to let go, the condition is reset, i.e. it does not stay signaled.

The derived class should override and implement the broadcast as required for the platform.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
signal
Derived class should release a single waiting thread.
public:
virtual void signal() = 0
Signals the condition, which allows one other thread return from a wait on the condition. Only one thread is allowed through, never more. If no threads are waiting, then this has no effect. So signal() is pulse type operation, i.e. it does not remain signaled.

The derived class must override this method and implement the signal operation as required for the platform.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
wait
Waits for the condition to be signaled or broadcast by another thread or process. An optional timeout can be provided, which defaults to an infinite wait if none is explicitly given.

The derived class should put the calling thread to sleep until another thread does a signal() or broadcast() call, or until the passed timeout expires (if a signal or broadcast does not arrive within the time out period.)


Overload 1
Derived classes should overload and block calling threads appropriately.
public:
virtual bool wait(long timeOut = - 1) = 0
This version of wait() does not accept a resource lock. It merely waits for up to the indicated timeout period for another thread to signal or broadcast the condition.

timeOut
The number of milliseconds to wait for the condition to become signaled. Defaults to -1, which means wait forever.

Return
true is returned is the condition was signalled. false is returned if the wait timed out.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 2
Derived classes should overload and block calling threads appropriately.
public:
virtual bool wait( IResourceLock& alock, long timeOut = - 1 ) = 0
The version that takes the lock will unlock it while it is blocked within the wait() call. The lock must be owned by the calling thread. When the thread is awakened again (either by timing out or by another thread calling signal() or broadcast()), the lock will be reaquired before returning.

aLock
is a resource lock object which will be unlocked while the thread waits. It must be owned by the calling thread.
timeOut
The number of milliseconds to wait for the condition to become signaled. Defaults to -1, which means wait forever.

Return
true is returned if the condition was signalled. false is returned if the wait timed out.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Miscellaneous Members


[view class]
Relock
public:
static void Relock(IResourceLock&, long times)

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
Unlock
public:
static long Unlock(IResourceLock&)

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


ICondition - Inherited Member Functions and Data

Inherited Public Functions

Inherited Public Data

Inherited Protected Functions

Inherited Protected Data