trap


A barrier is synchronization primitive that allows mutiple 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/trap.h>

class os_trap

Interface

Constructor
os_trap()
Constructs a trap.
add_to_trap
void add_to_trap( os_future& future )
Adds a future to the group of futures to manage.
get_next
os_future get_next()
Returns the next available future in the order that they were receive, blocking if one is not yet available.

Throws: os_thread_toolkit_error

remove_from_trap
bool remove_from_trap( os_future& future )
Returns true if the specified future is found and removes it from the group of futures to manage.
try_get_next
bool try_get_next( os_future& future )
Returns true if a future is immediately available and assigns future the available future, otherwise returns false without blocking.
size
int size() const
Returns the current number of futures being managed by the trap.

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