Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCMonitor Class Reference

A monitor is a re-entrant lock with a condition variable. More...

#include <mcllib/MCMonitor.h>

Inheritance diagram for MCMonitor:

MCMutex MCWaitNotifyAll MCNonCopy MCWaitNotify List of all members.

Public Member Functions

virtual void lock ()
 Lock the mutex associated with the monitor.
 MCMonitor ()
 Construct a monitor.
virtual void notify ()
 Notify a single waiter.
virtual void notifyAll ()
 Notify all waiters.
virtual void unlock ()
 Decrements the entry count associated with the monitor by one.
virtual bool wait (mcinterval_t interval)
 Wait for the monitor.
virtual void wait ()
 Wait indefinitely for the monitor.
virtual ~MCMonitor ()
 Destruct the monitor.

Detailed Description

A monitor is a re-entrant lock with a condition variable.

As with condition variables, the monitor uses a mutex but in this case, it is an integral part of the monitor object. Calling lock() on the monitor causes the mutex to be locked unless it is already locked by the calling thread in which case an "entry count" associated with the monitor is incremented. Calling unlock() on the monitor causes the entry count to be decremented, unlocking the mutex when it reaches zero. This provides the re-entrant semantics of the monitor.


Member Function Documentation

virtual void lock  )  [virtual]
 

Lock the mutex associated with the monitor.

If the calling thread already owns the mutex (has it locked) the entry count will be incremented by one.

Implements MCMutex.

virtual void unlock  )  [virtual]
 

Decrements the entry count associated with the monitor by one.

If it reaches zero, the mutex associated with the monitor is unlocked.

Implements MCMutex.

virtual bool wait mcinterval_t  interval  )  [virtual]
 

Wait for the monitor.

Parameters:
interval the maximum amount of time, in milliseconds, to wait
Returns:
true if the calling thread has entered the monitor.

false if the interval elapsed before the calling thread entered the monitor.

Implements MCWaitNotifyAll.


Generated on Wed Jan 12 19:05:49 2005 for MCLLIB by  doxygen 1.3.9.1