fawkes::InterruptibleBarrier Class Reference
[Multi-Threading tools]

A barrier is a synchronization tool which blocks until a given number of threads have reached the barrier. More...

#include <core/threading/barrier.h>

Inheritance diagram for fawkes::InterruptibleBarrier:

[legend]
List of all members.

Public Member Functions

 InterruptibleBarrier (unsigned int count)
 Constructor.
 InterruptibleBarrier (Mutex *mutex, unsigned int count)
 Constructor with custom mutex.
virtual ~InterruptibleBarrier ()
 Destructor.
bool wait (unsigned int timeout_sec, unsigned int timeout_nanosec)
 Wait for other threads.
virtual void wait ()
 Wait for other threads.
void interrupt () throw ()
 Interrupt the barrier.
void reset () throw ()
 Clears the barrier.
RefPtr< ThreadListpassed_threads ()
 Get a list of threads that passed the barrier.

Detailed Description

A barrier is a synchronization tool which blocks until a given number of threads have reached the barrier.

This particular implementations allows for giving a timeout after which the waiting is aborted.

For general information when a barrier is useful see the Barrier class.

Additionally to the general barrier features the InterruptibleBarrier::wait() can be given a timeout after which the waiting is aborted. Since the POSIX standard does not provide a timed wait for barriers this implementation uses a Mutex and WaitCondition internally to achieve the desired result.

See also:
Barrier
Author:
Tim Niemueller

Definition at line 38 of file interruptible_barrier.h.


Constructor & Destructor Documentation

fawkes::InterruptibleBarrier::InterruptibleBarrier ( unsigned int  count  ) 

Constructor.

Parameters:
count the number of threads to wait for

Definition at line 90 of file interruptible_barrier.cpp.

References fawkes::Barrier::_count.

fawkes::InterruptibleBarrier::InterruptibleBarrier ( Mutex mutex,
unsigned int  count 
)

Constructor with custom mutex.

Use this constructor only if you really know what you are doing. This constructor allows to pass a mutex that is used internally for the barrier. Note that in this case it is your duty to lock the mutex before the wait() and unlock afterwards! It combines features of a barrier and a wait condition.

Parameters:
mutex Mutex to use
count the number of threads to wait for

Definition at line 114 of file interruptible_barrier.cpp.

References fawkes::Barrier::_count.

fawkes::InterruptibleBarrier::~InterruptibleBarrier (  )  [virtual]

Destructor.

Definition at line 130 of file interruptible_barrier.cpp.


Member Function Documentation

void fawkes::InterruptibleBarrier::interrupt (  )  throw ()

Interrupt the barrier.

This will cause all threads currently waiting on the barrier to throw an exception and no further thread will wait. You have to call reset() the before you use this barrier the next time.

Definition at line 156 of file interruptible_barrier.cpp.

Referenced by FawkesMainThread::set_mainloop_thread().

RefPtr< ThreadList > fawkes::InterruptibleBarrier::passed_threads (  ) 

Get a list of threads that passed the barrier.

The list contains the threads that passed the barrier. With some book keeping outside of the barrier you can determine which threads you expected at the barrier but did not pass it.

Returns:
refptr to list of threads that passed the barrier.

Definition at line 143 of file interruptible_barrier.cpp.

Referenced by fawkes::ThreadList::wakeup_and_wait().

void fawkes::InterruptibleBarrier::reset ( void   )  throw ()

Clears the barrier.

Call this method when you want to use the barrier the next time after an interrupt or timeout occured. Make sure all threads that should have passed the barrier the last time did pass it.

Definition at line 171 of file interruptible_barrier.cpp.

References fawkes::Barrier::_count.

virtual void fawkes::InterruptibleBarrier::wait (  )  [inline, virtual]

Wait for other threads.

This method will block until as many threads have called wait as you have given count to the constructor.

Reimplemented from fawkes::Barrier.

Definition at line 46 of file interruptible_barrier.h.

bool fawkes::InterruptibleBarrier::wait ( unsigned int  timeout_sec,
unsigned int  timeout_nanosec 
)

Wait for other threads.

This method will block until as many threads have called wait as you have given count to the constructor. Note that if the barrier is interrupted or times out you need to call reset() to get the barrier into a re-usable state. It is your duty to make sure that all threads using the barrier are in a cohesive state.

Parameters:
timeout_sec relative timeout in seconds, added to timeout_nanosec
timeout_nanosec timeout in nanoseconds
Returns:
true, if the barrier was properly reached, false if the barrier timeout was reached and the wait did not finish properly.
Exceptions:
InterruptedException thrown if the barrier was forcefully interrupted by calling interrupt().

Definition at line 196 of file interruptible_barrier.cpp.

References fawkes::Barrier::_count, fawkes::Thread::current_thread(), and fawkes::Exception::print_trace().

Referenced by fawkes::NetworkConfiguration::set_mirror_mode(), and fawkes::ThreadList::wakeup_and_wait().


The documentation for this class was generated from the following files:
Generated on Tue Feb 22 13:31:38 2011 for Fawkes API by  doxygen 1.4.7