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

Comparing jsr166/src/main/java/util/concurrent/Phaser.java (file contents):
Revision 1.3 by jsr166, Sun Jul 26 17:48:58 2009 UTC vs.
Revision 1.4 by jsr166, Wed Jul 29 02:35:48 2009 UTC

# Line 30 | Line 30 | import java.util.concurrent.locks.LockSu
30   * zero, and advancing when all parties reach the barrier (wrapping
31   * around to zero after reaching {@code Integer.MAX_VALUE}).
32   *
33 < * <li> Like a CyclicBarrier, a Phaser may be repeatedly awaited.
34 < * Method {@code arriveAndAwaitAdvance} has effect analogous to
35 < * {@code CyclicBarrier.await}.  However, Phasers separate two
36 < * aspects of coordination, that may also be invoked independently:
33 > * <li> Like a {@code CyclicBarrier}, a Phaser may be repeatedly
34 > * awaited.  Method {@link #arriveAndAwaitAdvance} has effect
35 > * analogous to {@link java.util.concurrent.CyclicBarrier#await
36 > * CyclicBarrier.await}.  However, phasers separate two aspects of
37 > * coordination, that may also be invoked independently:
38   *
39   * <ul>
40   *
41 < *   <li> Arriving at a barrier. Methods {@code arrive} and
42 < *       {@code arriveAndDeregister} do not block, but return
41 > *   <li> Arriving at a barrier. Methods {@link #arrive} and
42 > *       {@link #arriveAndDeregister} do not block, but return
43   *       the phase value current upon entry to the method.
44   *
45 < *   <li> Awaiting others. Method {@code awaitAdvance} requires an
45 > *   <li> Awaiting others. Method {@link #awaitAdvance} requires an
46   *       argument indicating the entry phase, and returns when the
47   *       barrier advances to a new phase.
48   * </ul>
# Line 49 | Line 50 | import java.util.concurrent.locks.LockSu
50   *
51   * <li> Barrier actions, performed by the task triggering a phase
52   * advance while others may be waiting, are arranged by overriding
53 < * method {@code onAdvance}, that also controls termination.
53 > * method {@link #onAdvance}, that also controls termination.
54   * Overriding this method may be used to similar but more flexible
55 < * effect as providing a barrier action to a CyclicBarrier.
55 > * effect as providing a barrier action to a {@code CyclicBarrier}.
56   *
57   * <li> Phasers may enter a <em>termination</em> state in which all
58   * actions immediately return without updating phaser state or waiting
59   * for advance, and indicating (via a negative phase value) that
60   * execution is complete.  Termination is triggered by executing the
61   * overridable {@code onAdvance} method that is invoked each time the
62 < * barrier is about to be tripped. When a Phaser is controlling an
62 > * barrier is about to be tripped. When a phaser is controlling an
63   * action with a fixed number of iterations, it is often convenient to
64   * override this method to cause termination when the current phase
65 < * number reaches a threshold. Method {@code forceTermination} is also
65 > * number reaches a threshold. Method {@link #forceTermination} is also
66   * available to abruptly release waiting threads and allow them to
67   * terminate.
68   *
# Line 73 | Line 74 | import java.util.concurrent.locks.LockSu
74   *
75   * <li> By default, {@code awaitAdvance} continues to wait even if
76   * the waiting thread is interrupted. And unlike the case in
77 < * CyclicBarriers, exceptions encountered while tasks wait
77 > * {@code CyclicBarrier}, exceptions encountered while tasks wait
78   * interruptibly or with timeout do not change the state of the
79   * barrier. If necessary, you can perform any associated recovery
80   * within handlers of those exceptions, often after invoking
# Line 85 | Line 86 | import java.util.concurrent.locks.LockSu
86   *
87   * <p><b>Sample usages:</b>
88   *
89 < * <p>A Phaser may be used instead of a {@code CountDownLatch} to control
90 < * a one-shot action serving a variable number of parties. The typical
91 < * idiom is for the method setting this up to first register, then
92 < * start the actions, then deregister, as in:
89 > * <p>A {@code Phaser} may be used instead of a {@code CountDownLatch}
90 > * to control a one-shot action serving a variable number of
91 > * parties. The typical idiom is for the method setting this up to
92 > * first register, then start the actions, then deregister, as in:
93   *
94   *  <pre> {@code
95   * void runTasks(List<Runnable> list) {
# Line 137 | Line 138 | import java.util.concurrent.locks.LockSu
138   *   phaser.arriveAndDeregister(); // deregister self, don't wait
139   * }}</pre>
140   *
141 < * <p> To create a set of tasks using a tree of Phasers,
141 > * <p> To create a set of tasks using a tree of phasers,
142   * you could use code of the following form, assuming a
143 < * Task class with a constructor accepting a Phaser that
143 > * Task class with a constructor accepting a phaser that
144   * it registers for upon construction:
145   *  <pre> {@code
146   * void build(Task[] actions, int lo, int hi, Phaser b) {
# Line 247 | Line 248 | public class Phaser {
248      private final Phaser parent;
249  
250      /**
251 <     * The root of Phaser tree. Equals this if not in a tree.  Used to
251 >     * The root of phaser tree. Equals this if not in a tree.  Used to
252       * support faster state push-down.
253       */
254      private final Phaser root;
# Line 298 | Line 299 | public class Phaser {
299      }
300  
301      /**
302 <     * Creates a new Phaser without any initially registered parties,
302 >     * Creates a new phaser without any initially registered parties,
303       * initial phase number 0, and no parent. Any thread using this
304 <     * Phaser will need to first register for it.
304 >     * phaser will need to first register for it.
305       */
306      public Phaser() {
307          this(null);
308      }
309  
310      /**
311 <     * Creates a new Phaser with the given numbers of registered
311 >     * Creates a new phaser with the given numbers of registered
312       * unarrived parties, initial phase number 0, and no parent.
313       *
314       * @param parties the number of parties required to trip barrier
# Line 319 | Line 320 | public class Phaser {
320      }
321  
322      /**
323 <     * Creates a new Phaser with the given parent, without any
323 >     * Creates a new phaser with the given parent, without any
324       * initially registered parties. If parent is non-null this phaser
325       * is registered with the parent and its initial phase number is
326       * the same as that of parent phaser.
# Line 339 | Line 340 | public class Phaser {
340      }
341  
342      /**
343 <     * Creates a new Phaser with the given parent and numbers of
343 >     * Creates a new phaser with the given parent and numbers of
344       * registered unarrived parties. If parent is non-null, this phaser
345       * is registered with the parent and its initial phase number is
346       * the same as that of parent phaser.
# Line 673 | Line 674 | public class Phaser {
674      }
675  
676      /**
677 <     * Returns the parent of this phaser, or null if none.
677 >     * Returns the parent of this phaser, or {@code null} if none.
678       *
679 <     * @return the parent of this phaser, or null if none
679 >     * @return the parent of this phaser, or {@code null} if none
680       */
681      public Phaser getParent() {
682          return parent;
# Line 704 | Line 705 | public class Phaser {
705       * Overridable method to perform an action upon phase advance, and
706       * to control termination. This method is invoked whenever the
707       * barrier is tripped (and thus all other waiting parties are
708 <     * dormant). If it returns true, then, rather than advance the
709 <     * phase number, this barrier will be set to a final termination
710 <     * state, and subsequent calls to {@code isTerminated} will
711 <     * return true.
708 >     * dormant). If it returns {@code true}, then, rather than advance
709 >     * the phase number, this barrier will be set to a final
710 >     * termination state, and subsequent calls to {@link #isTerminated}
711 >     * will return true.
712       *
713 <     * <p> The default version returns true when the number of
713 >     * <p> The default version returns {@code true} when the number of
714       * registered parties is zero. Normally, overrides that arrange
715       * termination for other reasons should also preserve this
716       * property.
# Line 717 | Line 718 | public class Phaser {
718       * <p> You may override this method to perform an action with side
719       * effects visible to participating tasks, but it is in general
720       * only sensible to do so in designs where all parties register
721 <     * before any arrive, and all {@code awaitAdvance} at each phase.
721 >     * before any arrive, and all {@link #awaitAdvance} at each phase.
722       * Otherwise, you cannot ensure lack of interference. In
723       * particular, this method may be invoked more than once per
724       * transition if other parties successfully register while the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines