csp::Barrier Class Reference

Inheritance diagram for csp::Barrier:

boost::noncopyable List of all members.

Detailed Description

A barrier that multiple processes can synchronize on.

A barrier is an object that allows multiple parallel processes to synchronize. When one member of a barrier synchronizes, it will not complete that synchronization until all members of the barrier have synchronized. Barriers are described in the guide.

Barriers can be used for a wide variety of purposes, such as making sure a set of processes have all started up, or making sure they all finish a task before any of them continues, or to effect other sorts of synchronization between processes. Unlike channels, barriers do not communicate any data, but a synchronization can involve an arbitrary number of processes, from one upwards.

Unlike most barrier mechanisms offered by operating systems, processes may enroll on (join) the barrier at any time, and they may resign from (leave) the barrier at any time. They can even enroll, then resign, then enroll again and so on, as many times as they like.

Each synchronization cannot complete until all current members of the barrier have also synchronized. Imagine two processes, A and B, are enrolled on the barrier. A attempts to synchronize and is forced to wait (because B has not yet synchronized). If C now enrolls on the barrier, before B synchronizes, A's synchronization will not complete until both B and C have synchronized. C then synchronizes, meaning that A and C are waiting for B to synchronize. If B now resigns from the barrier, A and C will complete their synchronization because they are the only two remaining processes enrolled on the barrier and they are both waiting to synchronize.

All operations on a Barrier are done through BarrierEnd (or ScopedBarrierEnd). Ends can be obtained using the end() and enrolledEnd() methods.

C++CSP v1.x Compatibility

C++CSP v1.x had the Barrier class, but it was used directly, rather than with barrier-ends. This allowed some flexibility (enroll() and resign() could be called from anywhere) but repeated enroll() or resign() calls by the same process could not be detected, a pointer or reference to the Barrier had to be given to processes using the barrier. The previous Barrier model also would have missed out of some performance optimisations that the new Barrier has internally.

See also:
BarrierEnd


Public Member Functions

 Barrier ()
 Default constructor.
Mobile< BarrierEndend ()
 Gets a non-enrolled end of this barrier.
Mobile< BarrierEndenrolledEnd ()
 Gets an already enrolled end of this barrier.
 ~Barrier ()
 Destroys the barrier.


Constructor & Destructor Documentation

csp::Barrier::Barrier (  )  [inline]

Default constructor.

Constructs an empty barrier.

csp::Barrier::~Barrier (  )  [inline]

Destroys the barrier.

If any processes are still enrolled on the barrier, a BarrierError will be thrown because your application is in error.


Member Function Documentation

Mobile<BarrierEnd> csp::Barrier::end (  )  [inline]

Gets a non-enrolled end of this barrier.

See also:
BarrierEnd

ScopedBarrierEnd

Mobile

Mobile<BarrierEnd> csp::Barrier::enrolledEnd (  )  [inline]

Gets an already enrolled end of this barrier.

See also:
BarrierEnd

ScopedBarrierEnd

Mobile


Generated on Mon Aug 20 12:24:28 2007 for C++CSP2 by  doxygen 1.4.7