The CyclicBarrier uses an all-or-none breakage model for failed synchronization attempts: If a thread leaves a barrier point prematurely because of interruption, failure, or timeout, all other threads waiting at that barrier point will also leave abnormally via {@link BrokenBarrierException} (or{@link InterruptedException} if they too were interrupted at aboutthe same time). @since 1.5 @see CountDownLatch @author Doug Lea
If the barrier action does not rely on the parties being suspended when it is executed, then any of the threads in the party could execute that action when it is released. To facilitate this, each invocation of {@link #await} returns the arrival index of that thread at the barrier.You can then choose which thread should execute the barrier action, for example:
{@code}if (barrier.await() == 0) // log the completion of this iteration }}
The {@code CyclicBarrier} uses an all-or-none breakage modelfor failed synchronization attempts: If a thread leaves a barrier point prematurely because of interruption, failure, or timeout, all other threads waiting at that barrier point will also leave abnormally via {@link BrokenBarrierException} (or{@link InterruptedException} if they too were interrupted at aboutthe same time).
Memory consistency effects: Actions in a thread prior to calling {@code await()}happen-before actions that are part of the barrier action, which in turn happen-before actions following a successful return from the corresponding {@code await()} in other threads. @since 1.5 @see CountDownLatch @author Doug Lea
|
|
|
|