Base Class
#include <rw/sync/RWBarrier.h>
Use an RWBarrier object to synchronize a number of concurrent threads at a specific point in their processing. Each thread indicates that it has reached the "barrier" by calling the wait() member function. Each thread is blocked by the call to wait() until the number of threads specified in the RWBarrier constructor have all called wait(). When the last thread calls wait(), all threads waiting at the barrier are unblocked, making them eligible for execution.
Initializing an RWBarrier with a zero count is not legal; an assertion will be triggered in debug mode. Using an RWBarrier with a count different than the number of threads able to perform a wait() on that RWBarrier is outside the intended use of the class. There is no diagnostic available to detect this condition.
An RWBarrier's count may be changed after initialization by using the setCount(int) function. No threads must be blocked in wait() when this function is called. In debug mode, if there are threads blocked in wait(), an assertion will be triggered; in release mode, an exception will be thrown.
When an RWBarrier is destroyed, no threads should be blocked in the wait() function. When the library is built in debug mode, an assertion will be raised if there are threads waiting when the RWBarrier is destructed.
#include <rw/thread/rwtMakeThreadFunction.h> #include <rw/sync/RWBarrier.h> // for RWBarrier void func(RWBarrier* barrier) { // do initialization ... // wait for all threads to complete initialization barrier->wait(); } main() { RWBarrier barrier(3); RWThread t1 = rwtMakeThreadFunction(func, &barrier); RWThread t2 = rwtMakeThreadFunction(func, &barrier); t1.start(); t2.start(); barrier.wait(); // Wait for t1 and t2 to complete // initialization. t1.join(); t2.join(); }
RWBarrier(int count=1);
Constructs a barrier for synchronizing count threads, where count must be greater than 0. A default count is provided for default destruction. The default count is 1, which is not a particularly useful count; however, the internal count may be changed following construction using the setCount() method.
~RWBarrier(void);
Triggers an assertion failure in debug mode if there are any threads blocked in wait().
void
setCount(int count);
Sets the barrier count to count. The count must be greater than or equal to 1. There must be no threads blocked in wait() when this function is called.
void wait(void);
Each thread calls wait() when it reaches its synchronization point. The threads block in wait() until count threads have called wait(). When the last thread enters wait(), all the threads are released.
RWBarrier(const RWBarrier&);
Copy construction prohibited.
RWBarrier&
operator=(const RWBarrier&);
Assignment prohibited.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.