[#absl-Barrier] = xref:absl.adoc[absl]::Barrier :relfileprefix: ../ :mrdocs: A barrier that blocks threads until a threshold of threads reach it. == Synopsis Declared in `<absl/synchronization/barrier.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Barrier; ---- == Description 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: [,cpp] ---- // 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. ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Barrier/2constructor-0bb.adoc[`Barrier`] [.small]#[constructor]# | Constructors | xref:absl/Barrier/operator_assign.adoc[`operator=`] [.small]#[deleted]# | Deleted copy assignment; `Barrier` is not copyable. | xref:absl/Barrier/Block.adoc[`Block`] | Blocks the calling thread until the thread threshold is reached. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#