If you can read this text, it means you are not experiencing this website at its best. This website is designed for used with a standards-compliant browser.
Current version: 2.3.2
ZThreads
A platform-independent, multi-threading and synchronization library for C++
Home Documentation Downloads CVS Contact
Barrier< Count, LockType > Class Template Reference

#include <Barrier.h>

Inheritance diagram for Barrier< Count, LockType >:
Waitable NonCopyable

Public Member Functions

 Barrier ()
 Create a Barrier.
 
 Barrier (const Task &task)
 
virtual ~Barrier ()
 Destroy this Barrier.
 
virtual void wait ()
 
virtual bool wait (unsigned long timeout)
 
void shatter ()
 
void reset ()
 
- Public Member Functions inherited from Waitable
virtual ~Waitable ()
 Destroy a Waitable object.

 
virtual void wait ()=0
 
virtual bool wait (unsigned long timeout)=0
 

Detailed Description

template<unsigned int Count, class LockType>
class ZThread::Barrier< Count, LockType >
Author
Eric Crahen http://www.code-foo.com
Date
<2003-07-16T09:54:01-0400>
Version
2.2.1

A Barrier is a Waitable object that serves as synchronization points for a set of threads. A Barrier is constructed for a fixed number (N) of threads. Threads attempting to wait() on a Barrier ( 1 - N) will block until the Nth thread arrives. The Nth thread will awaken all the the others.

An optional Runnable command may be associated with the Barrier. This will be run() when the Nth thread arrives and Barrier is not broken.

Error Checking

A Barrier uses an all-or-nothing. All threads involved must successfully meet at Barrier. If any one of those threads leaves before all the threads have (as the result of an error or exception) then all threads present at the Barrier will throw BrokenBarrier_Exception.

A broken Barrier will cause all threads attempting to wait() on it to throw a BrokenBarrier_Exception.

A Barrier will remain 'broken', until it is manually reset().

Constructor & Destructor Documentation

◆ Barrier()

Barrier ( const Task task)
inline

Create a Barrier that executes the given task when all threads arrive without error

Parameters
taskTask to associate with this Barrier

Member Function Documentation

◆ reset()

void reset ( )
inline

Reset the Barrier.

Postcondition
the Barrier is no longer Broken and can be used again.

◆ shatter()

void shatter ( )
inline

Break the Barrier ending the wait for any threads that were waiting on the barrier.

Postcondition
the Barrier is broken, all waiting threads will throw the BrokenBarrier_Exception

◆ wait() [1/2]

virtual void wait ( )
inlinevirtual

Enter barrier and wait for the other threads to arrive. This can block for an indefinite amount of time.

Exceptions
BrokenBarrier_Exceptionthrown when any thread has left a wait on this Barrier as a result of an error.
Interrupted_Exceptionthrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending a wait for one thread and breaking the barrier for all threads
See also
Waitable::wait()
Postcondition
If no exception was thrown, all threads have successfully arrived
If an exception was thrown, the barrier is broken

Implements Waitable.

◆ wait() [2/2]

virtual bool wait ( unsigned long  timeout)
inlinevirtual

Enter barrier and wait for the other threads to arrive. This can block up to the amount of time specified with the timeout parameter. The barrier will not break if a thread leaves this function due to a timeout.

Parameters
timeoutmaximum amount of time, in milliseconds, to wait before
Returns
  • true if the set of tasks being wait for complete before timeout milliseconds elapse.
  • false otherwise.
Exceptions
BrokenBarrier_Exceptionthrown when any thread has left a wait on this Barrier as a result of an error.
Interrupted_Exceptionthrown when the calling thread is interrupted. A thread may be interrupted at any time, prematurely ending a wait for one thread and breaking the barrier for all threads
See also
Waitable::wait(unsigned long timeout)
Postcondition
If no exception was thrown, all threads have successfully arrived
If an exception was thrown, the barrier is broken

Implements Waitable.


The documentation for this class was generated from the following file: