#include <Latch.h>
Inheritance diagram for ZThread::Latch::
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) |
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 ... } }
|
Create a new Latch with the given count
|
|
Destroy this Latch |
|
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
Reimplemented from ZThread::Lockable. |
|
Releasing a Latch decrements the internal count and brings it that much closer to being acquire()able
Reimplemented from ZThread::Lockable. |
|
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
Reimplemented from ZThread::Lockable. |