Inheritance diagram for csp::BarrierEnd:
Barriers cannot be used directly, instead each process enrolled on the barrier must possess an end of the barrier.
Barrier ends are usually given out in the form Mobile<BarrierEnd>. Mobile is used to ensure that barrier-ends are not unintentionally duplicated, which would lead to confusion. While it may not be immediately apparent, using BarrierEnd without Mobile would cause a lot of trouble. See the Mobile class for more details on its use and semantics. If you do wish to copy a BarrierEnd to pass to a sub-process, you can use the makeNonEnrolledCopy() or makeEnrolledCopy() functions accordingly.
A barrier end can be in one of two states - enrolled or non-enrolled. Syncing is only possible when the end is enrolled. Multiple enroll() calls will not cause an error, and neither will multiple resign() calls, provided they are made from the same process that will make/has made the sync() calls (see below). A barrier end instance will always be associated with the same barrier.
Once an end is enrolled on the barrier, its sync() calls must all be from the same process. Calling sync() on the same barrier end from two different processes (concurrently or consecutively) will cause undefined behaviour. If you wish to transfer a barrier end from one process to another, you must first resign() in the original process and then call enroll() in the new process. Alternatively, the better method is probably to create a new end for the new process (either from the original Barrier or using makeEnrolledCopy() ) and resign from the original end.
Public Member Functions | |
void | enroll () |
Enrolls on the barrier. | |
Mobile< BarrierEnd > | makeEnrolledCopy () |
Makes a copy of this BarrierEnd (that uses the same Barrier) that is already enrolled on the barrier. | |
Mobile< BarrierEnd > | makeNonEnrolledCopy () |
Makes a copy of this BarrierEnd (that uses the same Barrier) that is not enrolled on the barrier. | |
bool | operator< (const BarrierEnd &end) |
All BarrierEnd instances are inherently distinct. | |
bool | operator== (const BarrierEnd &end) |
All BarrierEnd instances are inherently distinct. | |
void | resign () |
Resigns from the barrier. | |
void | sync () |
Synchronises with the barrier. | |
~BarrierEnd () | |
The destructor. |
csp::BarrierEnd::~BarrierEnd | ( | ) | [inline] |
The destructor.
Throws a BarrierError if the BarrierEnd is still enrolled, and the destructor is not being called because of a previously thrown exception.
Destroying a BarrierEnd while it is still enrolled is an error. The destructor resigns but throws a BarrierError afterwards (if safe to do so - it will not be thrown if the destructor is being called because of stack-unwinding). If BarrierError is thrown, your application is in error and needs to be fixed. Make sure you always resign from a BarrierEnd before it is destroyed.
If you wish this resignation to be done automatically without a BarrierError being thrown, please look at ScopedBarrierEnd instead.
void csp::BarrierEnd::enroll | ( | ) | [inline] |
Enrolls on the barrier.
This must be done by the process that wishes to enroll (i.e. the process that will then make the sync() and resign() calls).
Enroll may temporarily block.
If you want to construct a pre-enrolled barrier please look at the Barrier::enrolledEnd() and makeEnrolledCopy() functions.
Calling enroll() twice on the same BarrierEnd (without a resign() call inbetween) in the same process is guaranteed to have no effect (i.e. it will not enroll on the barrier twice).
void csp::BarrierEnd::resign | ( | ) | [inline] |
Resigns from the barrier.
This must be done by the same process that has previously called enroll() on the barrier.
Resign may temporarily block.
After resignation, you may call enroll() again to re-enroll on the same barrier.
Calling resign() on a BarrierEnd that the process is not currently enrolled on is guaranteed to have no effect.
void csp::BarrierEnd::sync | ( | ) | [inline] |
Synchronises with the barrier.
This must be done by the same process that has previously called enroll() on the barrier (and has not yet called resign() since).
Sync will block until all the other processes on the barrier have also called sync().
It is an error to call sync() on a currently non-enrolled barrier end. This will result in a BarrierError being thrown.
Mobile<BarrierEnd> csp::BarrierEnd::makeEnrolledCopy | ( | ) | [inline] |
Makes a copy of this BarrierEnd (that uses the same Barrier) that is already enrolled on the barrier.
Mobile<BarrierEnd> csp::BarrierEnd::makeNonEnrolledCopy | ( | ) | [inline] |
Makes a copy of this BarrierEnd (that uses the same Barrier) that is not enrolled on the barrier.
bool csp::BarrierEnd::operator== | ( | const BarrierEnd & | end | ) | [inline] |
All BarrierEnd instances are inherently distinct.
However, they are deemed to be equal if they use the same underlying Barrier. No consideration is given to whether either of them is currently enrolled.
bool csp::BarrierEnd::operator< | ( | const BarrierEnd & | end | ) | [inline] |
All BarrierEnd instances are inherently distinct.
This ordering is based on the underlying barrier. No consideration is given to whether either of them is currently enrolled.