Inheritance diagram for csp::ScopedBarrierEnd:
ScopedBarrierEnd applies the scoped concept to the end of a barrier. It enrolls on the barrier when constructed, and when it is destroyed it resigns from the barrier, so that you do not have to remember to explicitly resign from the barrier.
It is used as follows:
Barrier barrier; ... { ScopedBarrierEnd end(barrier.end()); //You can use barrier.end() or barrier.enrolledEnd() above //Either way, the barrier will be enrolled upon ... end.sync(); ... } //Here, the ScopedBarrierEnd is destroyed, and the barrier is resigned from automatically
The automatic resignation from the barrier is useful for two reasons - firstly, it prevents you from forgetting to do so. Secondly, the resignation automatically occurs even if an exception is thrown. Otherwise you would have to declare a BarrierEnd outside of the try block and place a resignation in the catch block.
Some may find this automatic resignation to be too hidden, in the invisible destruction of the ScopedBarrierEnd. If this is the case, look at using the more explicit BarrierEnd instead.
As its name suggests, ScopedBarrierEnd must only be declared as a local scope on-the-stack variable. Allocating it on the heap loses all the benefits, as does allocating it as a class variable.
See the Scoped page for more information on the scoped classes.
Public Member Functions | |
ScopedBarrierEnd (const Mobile< BarrierEnd > &_end) | |
Constructs a ScopedBarrierEnd using the given BarrierEnd. | |
void | sync () |
Syncs on the barrier. | |
~ScopedBarrierEnd () | |
Destructor - automatically resigns the ScopedBarrierEnd from the Barrier. |
csp::ScopedBarrierEnd::ScopedBarrierEnd | ( | const Mobile< BarrierEnd > & | _end | ) | [inline, explicit] |
Constructs a ScopedBarrierEnd using the given BarrierEnd.
The supplied BarrierEnd can either be enrolled or not-enrolled. Either way, the ScopedBarrierEnd constructor will ensure that it is enrolled on the barrier.
Due to Mobile semantics, the passed Mobile will be blanked.
_end | A BarrierEnd of the Barrier to use |
csp::ScopedBarrierEnd::~ScopedBarrierEnd | ( | ) | [inline] |
Destructor - automatically resigns the ScopedBarrierEnd from the Barrier.
void csp::ScopedBarrierEnd::sync | ( | ) | [inline] |
Syncs on the barrier.
Sync will block until all the processes enrolled on the barrier have also synced.