23 |
|
* |
24 |
|
* <p><b>Sample usage:</b> Here is an example of |
25 |
|
* using a barrier in a parallel decomposition design: |
26 |
< |
* <pre> |
26 |
> |
* |
27 |
> |
* <pre> {@code |
28 |
|
* class Solver { |
29 |
|
* final int N; |
30 |
|
* final float[][] data; |
62 |
|
* |
63 |
|
* waitUntilDone(); |
64 |
|
* } |
65 |
< |
* } |
66 |
< |
* </pre> |
65 |
> |
* }}</pre> |
66 |
> |
* |
67 |
|
* Here, each worker thread processes a row of the matrix then waits at the |
68 |
|
* barrier until all rows have been processed. When all rows are processed |
69 |
|
* the supplied {@link Runnable} barrier action is executed and merges the |
77 |
|
* {@link #await} returns the arrival index of that thread at the barrier. |
78 |
|
* You can then choose which thread should execute the barrier action, for |
79 |
|
* example: |
80 |
< |
* <pre> if (barrier.await() == 0) { |
81 |
< |
* // log the completion of this iteration |
82 |
< |
* }</pre> |
80 |
> |
* <pre> {@code |
81 |
> |
* if (barrier.await() == 0) { |
82 |
> |
* // log the completion of this iteration |
83 |
> |
* }}</pre> |
84 |
|
* |
85 |
|
* <p>The <tt>CyclicBarrier</tt> uses an all-or-none breakage model |
86 |
|
* for failed synchronization attempts: If a thread leaves a barrier |