barrier


A barrier is synchronization primitive that allows multiple threads to reach a specific point and wait before they all can proceed. For example, threads completing a matrix computation can wait at a barrier until all threads have finished the current phase of the parallel computation, before they all can proceed to the next phase of the computation. A barrier object contains a counter which is initialized with a thread count when the barrier is created. The thread count represents the number of waiting threads that can wait in the barrier group. When each thread reaches the barrier it calls the barrier wait() method. The wait() method decrements the thread counter. When the last thread reaches the barrier and calls the wait() method, the count goes to zero. The barrier object then unblocks all the waiting threads in the barrier group to proceed.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/barrier.h>

class os_barrier

Interface

Constructor
os_barrier( unsigned int thread_count )
Constructs a barrier with thread_count indicating the number of threads to block before allowing them to proceed.

Throws: os_thread_toolkit_error

Destructor
~os_barrier()
Destroys this barrier, releasing any associated system resources.
print
void print( ostream& stream ) const
Prints to stream .

Throws: os_thread_toolkit_error

wait
bool wait()
Blocks until all members of the barrier reach the barrier. Returns true  for the last thread that unblocks all other waiting threads.

Throws: os_thread_toolkit_error


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.