Inheritance diagram for csp::Barrier:
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.
Public Member Functions | |
Barrier () | |
Default constructor. | |
Mobile< BarrierEnd > | end () |
Gets a non-enrolled end of this barrier. | |
Mobile< BarrierEnd > | enrolledEnd () |
Gets an already enrolled end of this barrier. | |
~Barrier () | |
Destroys the barrier. |
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.
Mobile<BarrierEnd> csp::Barrier::end | ( | ) | [inline] |
Mobile<BarrierEnd> csp::Barrier::enrolledEnd | ( | ) | [inline] |