Main Page   Namespace List   Class Hierarchy   Compound List   Compound Members  

ZThread::Latch Class Template Reference

#include <Latch.h>

Inheritance diagram for ZThread::Latch::

ZThread::Lockable List of all members.

Public Methods

 Latch (int initialCount=1) throw (Synchronization_Exception)
virtual ~Latch () throw ()
virtual void acquire () throw (Synchronization_Exception)
virtual bool tryAcquire (unsigned long timeout) throw (Synchronization_Exception)
virtual void release () throw (Synchronization_Exception)

Detailed Description

template<class LOCK = Mutex> class ZThread::Latch

Author:
Eric Crahen
Version:
1.3.2
Date:
04-01-2001

A Latch object is a non-thread specific one time switch. That is to say that the same thread can release the latch and then acquire it. Also, it is a basically one time switch, once it has been activated its state will remain the same.

It is created with an initial count {n}. Before a section can be entered that is <Guard>ed by a Latch, that Latch must be released n times.

A simple example: This telephone simulation won't start until someone Ring()s (makes a call) and someone Answer()s

 Latch enoughCallers(2);

 void Ring() {
   enoughCallers.release();
 }

 void Answer() {
   enoughCallers.release();
 }

 void MainTelephoneSimulationLoop() {

   Guard<Latch> g(enoughCallers);

   for(;;) {

   ... finally enough callers ...

   }

 }


Constructor & Destructor Documentation

Latch ( int initialCount = 1 ) throw (Synchronization_Exception) [inline]
 

Create a new Latch with the given count

Parameters:
int   - initial count (default 1)
Exceptions:
Initialization_Exception  
Parameters:
initialCount  

~Latch ( ) throw () [inline, virtual]
 

Destroy this Latch


Member Function Documentation

void acquire ( ) throw (Synchronization_Exception) [inline, virtual]
 

Acquire()ing a Latch will block the calling thread until the Latch has been released enough times. The number of times a Latch must be released is determined during construction

Exceptions:
Synchronization_Exception  

Reimplemented from ZThread::Lockable.

void release ( ) throw (Synchronization_Exception) [inline, virtual]
 

Releasing a Latch decrements the internal count and brings it that much closer to being acquire()able

Exceptions:
Synchronization_Exception  

Reimplemented from ZThread::Lockable.

bool tryAcquire ( unsigned long timeout ) throw (Synchronization_Exception) [inline, virtual]
 

Functions in a manner similar to the acquire() method, but can timeout and fail after a given amount of time

The behavior of this method depends on your choice of the LOCK. Lockable objects, like the FastMutex, do not support the tryAcquire method and will cause this method to block longer than expected

Parameters:
long   - timeout (milliseconds)
Exceptions:
Synchronization_Exception  
Parameters:
timeout  

Reimplemented from ZThread::Lockable.


The documentation for this class was generated from the following file:
Generated at Fri Aug 31 09:08:00 2001 for ZThread by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001