Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeMonitor Class Reference

a java style thread monitor, but better! More...

#include <cascade/interthread/CascadeMonitor.h>

Inheritance diagram for CascadeMonitor:

CascadeObject List of all members.

Public Member Functions

 CascadeMonitor ()
virtual ~CascadeMonitor ()
void Enter ()
void Exit ()
void Notify ()
void Broadcast ()
bool WaitForNotification (u32 nTimeoutMilliseconds=0)

Detailed Description

a java style thread monitor, but better!

Skip the description

CascadeMonitor provides a thread-safe monitor that provides mutex-like protection with notification condition variables.


class CascadeMonitor


Constructor & Destructor Documentation

CascadeMonitor::CascadeMonitor  ) 
 

the default constructor - lightweight

This default constructor is lightweight.

virtual CascadeMonitor::~CascadeMonitor  )  [virtual]
 

destructor

The destructor.


Member Function Documentation

void CascadeMonitor::Broadcast  ) 
 

broadcasts the monitor's condition

Broadcast() operates as Notify() does but wakes up all threads (not just one) that are waiting for notification on this monitor.

See also:
Enter(), Exit()

Notify()

WaitForNotification()

void CascadeMonitor::Enter  ) 
 

enters the monitor

Call Enter() to enter the monitor. Once you have entered the monitor, you own access to the monitored data. (It's like entering a critical section). You MUST enter the monitor prior to calling WaitForNotification() or your wait will be a 'naked' wait.

See also:
Exit()

WaitForNotification()

void CascadeMonitor::Exit  ) 
 

exits the monitor

Call Exit() to exit the monitor. Once you call Exit() other threads may Enter() the monitor.

See also:
Enter()

void CascadeMonitor::Notify  ) 
 

notifies the monitor's condition

Call Notify() to wake up one (1) thread that is waiting for notification on this monitor. There are two ways to call Notify() - with the monitor entered, or not. The latter is referred to as a naked notify and is used when the monitor is not protecting access to external data. The more common case is the non-naked notify:

             monitor.Enter();
             someMonitoredDataValue = 3;  // fiddle with the monitored data
             monitor.Notify();            // notify that we've appropriately fiddled with the monitored data
             monitor.Exit();              // notified thread will wake up (and re-enter the monitor) when Exit() is called.
Note:
In the example above if you Exit() before you Notify() your Notify will be a naked notify - (not synchronized with the monitored data).
See also:
Enter(), Exit()

Broadcast()

WaitForNotification()

bool CascadeMonitor::WaitForNotification u32  nTimeoutMilliseconds = 0  ) 
 

waits for a monitor's condition to be notified or broadcast by another thread

WaitForNotification() causes the calling thread to wait until another thread notifies the monitor (with either Broadcast() or Notify()), or until nTimeoutMilliseconds milliseconds have expired (0 means infinite). If the function returns true, the monitor was notified. If the function returns false, the outcome was a timeout. Note that like Notify() and B%roadcast(), Waits are naked-Waits if the monitor is not entered when WaitForNotification() is called. Naked waits are almost never used, and are only useful when there is no monitored data or when there is no interest in the monitored data. The more-usual case is the non-naked Wait:

             monitor.Enter();
             if (someMonitoredDataValue != 3)    // check to see if I should wait
                 monitor.WaitForNotification();  // waiting will exit the monitor for the duration of the wait
             ASSERT(someMonitoredDataValue == 3);// after waiting I have automatically re-entered the monitor
             monitor.Exit();                     // I'm still in the monitor, so must exit
Parameters:
nTimeoutMilliseconds the timeout for the wait
Returns:
true if the notification was signalled, false on timeout
See also:
Enter(), Exit()

Notify(), Broadcast()


The documentation for this class was generated from the following file:
Generated on Sun Jul 24 14:27:19 2005 for Cascade Library by  doxygen 1.4.1