The barrier module provides a primitive for synchronizing the progress of a group of threads.
This class represents a barrier across which threads may only travel in groups of a specific size.
int numThreads = 10;
auto barrier = new Barrier( numThreads );
auto synInfo = new Object;
int numReady = 0;
int numPassed = 0;
void threadFn()
{
synchronized( synInfo )
{
++numReady;
}
barrier.wait();
synchronized( synInfo )
{
++numPassed;
}
}
auto group = new ThreadGroup;
for ( int i = 0; i < numThreads; ++i )
{
group.create( &threadFn );
}
group.joinAll();
assert( numReady == numThreads && numPassed == numThreads );
Initializes a barrier object which releases threads in groups of limit in size.
uint limit
| The number of waiting threads to release in unison. |
Wait for the pre-determined number of threads and then proceed.
© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/core_sync_barrier.html