Synchronizes a number of concurrent threads at a specific point in their processing. More...
#include <rw/sync/RWBarrier.h>
Public Member Functions | |
RWBarrier (int count=1) | |
~RWBarrier () | |
void | setCount (int count) |
void | wait () |
Private Member Functions | |
RWBarrier (const RWBarrier &second) | |
RWBarrier & | operator= (const RWBarrier &second) |
RWBarrier synchronizes 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, and causes an assertion to 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.
The count of an RWBarrier may be changed after initialization by using the setCount(int) function. When calling this function, make sure that no threads are blocked in wait(). If threads are blocked in wait(), an assertion is triggered in debug mode; in release mode, an exception is thrown.
When an RWBarrier is destroyed, no threads should be blocked in the wait() function. When the module is built in debug mode, an assertion is raised if there are threads waiting when the RWBarrier is destructed.
RWBarrier::RWBarrier | ( | int | count = 1 | ) |
Constructs a barrier for synchronizing count threads, where count must be greater than 0. A default count of 1 is provided for default construction. This can be changed following construction using the setCount() method.
RWBarrier::~RWBarrier | ( | ) |
Destructor. Triggers an assertion failure in debug mode if there are any threads blocked in wait().
|
private |
Copy construction prohibited.
void RWBarrier::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 RWBarrier::wait | ( | ) |
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 threads are released.
Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |