A barrier that blocks threads until a threshold of threads reach it.
Declared in <absl/synchronization/barrier.h>
class Barrier;
This class creates a barrier which blocks threads until a prespecified threshold of threads (num_threads) utilizes the barrier. A thread utilizes the Barrier by calling Block() on the barrier, which will block that thread; no call to Block() will return until num_threads threads have called it.
Exactly one call to Block() will return true, which is then responsible for destroying the barrier; because stack allocation will cause the barrier to be deleted when it is out of scope, barriers should not be stack allocated.
Example:
// Main thread creates a `Barrier`:
barrier = new Barrier(num_threads);
// Each participating thread could then call:
if (barrier->Block()) delete barrier; // Exactly one call to `Block()`
// returns `true`; that call
// deletes the barrier.
| Name | Description |
|---|---|
Barrier [constructor] | Constructors |
operator= [deleted] | Deleted copy assignment; Barrier is not copyable. |
Block | Blocks the calling thread until the thread threshold is reached. |