2 * The barrier module provides a primitive for synchronizing the progress of
5 * Copyright: Copyright Sean Kelly 2005 - 2009.
6 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8 * Source: $(DRUNTIMESRC core/sync/_barrier.d)
11 /* Copyright Sean Kelly 2005 - 2009.
12 * Distributed under the Boost Software License, Version 1.0.
13 * (See accompanying file LICENSE or copy at
14 * http://www.boost.org/LICENSE_1_0.txt)
16 module core.sync.barrier;
19 public import core.sync.exception;
20 private import core.sync.condition;
21 private import core.sync.mutex;
25 private import core.stdc.errno;
26 private import core.sys.posix.pthread;
30 ////////////////////////////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////////////////////////////
38 * This class represents a barrier across which threads may only travel in
39 * groups of a specific size.
43 ////////////////////////////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////////////////////////////
49 * Initializes a barrier object which releases threads in groups of limit
53 * limit = The number of waiting threads to release in unison.
66 m_cond = new Condition( m_lock );
73 ////////////////////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////////////////////
79 * Wait for the pre-determined number of threads and then proceed.
86 synchronized( m_lock )
96 while ( group == m_group )
111 ////////////////////////////////////////////////////////////////////////////////
113 ////////////////////////////////////////////////////////////////////////////////
118 private import core.thread;
124 auto barrier = new Barrier( numThreads );
125 auto synInfo = new Object;
131 synchronized( synInfo )
136 synchronized( synInfo )
142 auto group = new ThreadGroup;
144 for ( int i = 0; i < numThreads; ++i )
146 group.create( &threadFn );
149 assert( numReady == numThreads && numPassed == numThreads );