ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/Phaser.java
(Generate patch)

Comparing jsr166/src/jsr166y/Phaser.java (file contents):
Revision 1.44 by dl, Tue Aug 25 16:32:28 2009 UTC vs.
Revision 1.45 by jsr166, Tue Aug 25 16:50:24 2009 UTC

# Line 142 | Line 142 | import java.util.concurrent.locks.LockSu
142   *     }
143   *   };
144   *   phaser.register();
145 < *   for (Runnable task : tasks) {
145 > *   for (final Runnable task : tasks) {
146   *     phaser.register();
147   *     new Thread() {
148   *       public void run() {
149   *         do {
150   *           task.run();
151   *           phaser.arriveAndAwaitAdvance();
152 < *         } while(!phaser.isTerminated();
152 > *         } while (!phaser.isTerminated());
153   *       }
154   *     }.start();
155   *   }
# Line 158 | Line 158 | import java.util.concurrent.locks.LockSu
158   *
159   * If the main task must later await termination, it
160   * may re-register and then execute a similar loop:
161 < * <pre> {@code
161 > *  <pre> {@code
162   *   // ...
163   *   phaser.register();
164   *   while (!phaser.isTerminated())
165 < *     phaser.arriveAndAwaitAdvance();
166 < * }</pre>
165 > *     phaser.arriveAndAwaitAdvance();}</pre>
166   *
167 < * Related constructions may be used to await particular phase numbers
167 > * <p>Related constructions may be used to await particular phase numbers
168   * in contexts where you are sure that the phase will never wrap around
169   * {@code Integer.MAX_VALUE}. For example:
170   *
171 < * <pre> {@code
172 < *   void awaitPhase(Phaser phaser, int phase) {
173 < *     int p = phaser.register(); // assumes caller not already registered
174 < *     while (p < phase) {
175 < *       if (phaser.isTerminated())
176 < *         // ... deal with unexpected termination
177 < *       else
178 < *         p = phaser.arriveAndAwaitAdvance();
180 < *     }
181 < *     phaser.arriveAndDeregister();
171 > *  <pre> {@code
172 > * void awaitPhase(Phaser phaser, int phase) {
173 > *   int p = phaser.register(); // assumes caller not already registered
174 > *   while (p < phase) {
175 > *     if (phaser.isTerminated())
176 > *       // ... deal with unexpected termination
177 > *     else
178 > *       p = phaser.arriveAndAwaitAdvance();
179   *   }
180 < * }</pre>
180 > *   phaser.arriveAndDeregister();
181 > * }}</pre>
182   *
183   *
184   * <p>To create a set of tasks using a tree of phasers,
185   * you could use code of the following form, assuming a
186   * Task class with a constructor accepting a phaser that
187   * it registers for upon construction:
188 + *
189   *  <pre> {@code
190   * void build(Task[] actions, int lo, int hi, Phaser ph) {
191   *   if (hi - lo > TASKS_PER_PHASER) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines