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.38 by dl, Mon Aug 24 12:11:00 2009 UTC vs.
Revision 1.42 by dl, Mon Aug 24 18:37:15 2009 UTC

# Line 35 | Line 35 | import java.util.concurrent.locks.LockSu
35   * #arriveAndAwaitAdvance} has effect analogous to {@link
36   * java.util.concurrent.CyclicBarrier#await CyclicBarrier.await}. Each
37   * generation of a {@code Phaser} has an associated phase number. The
38 < * phase number starts at zero, amd advances when all parties arrive
38 > * phase number starts at zero, and advances when all parties arrive
39   * at the barrier, wrapping around to zero after reaching {@code
40   * Integer.MAX_VALUE}. The use of phase numbers enables independent
41   * control of actions upon arrival at a barrier and upon awaiting
# Line 62 | Line 62 | import java.util.concurrent.locks.LockSu
62   *       the barrier advances to (or is already at) a different phase.
63   *       Unlike similar constructions using {@code CyclicBarrier},
64   *       method {@code awaitAdvance} continues to wait even if the
65 < *       waiting thread is interrupted. (Interruptible and timeout
66 < *       versions are also available.)  Exceptions encountered while
65 > *       waiting thread is interrupted. Interruptible and timeout
66 > *       versions are also available, but exceptions encountered while
67   *       tasks wait interruptibly or with timeout do not change the
68   *       state of the barrier. If necessary, you can perform any
69   *       associated recovery within handlers of those exceptions,
# Line 75 | Line 75 | import java.util.concurrent.locks.LockSu
75   * </ul>
76   *
77   * <p> <b>Termination.</b> A {@code Phaser} may enter a
78 < * <em>termination</em> state in which all actions immediately return
79 < * without updating phaser state or waiting for advance, and
80 < * indicating (via a negative phase value) that execution is complete.
81 < * Termination is triggered when an invocation of {@code onAdvance}
82 < * returns {@code true}.  As illustrated below, when phasers control
83 < * actions with a fixed number of iterations, it is often convenient
84 < * to override this method to cause termination when the current phase
85 < * number reaches a threshold. Method {@link #forceTermination} is
86 < * also available to abruptly release waiting threads and allow them
87 < * to terminate.
78 > * <em>termination</em> state in which all synchronization methods
79 > * immediately return without updating phaser state or waiting for
80 > * advance, and indicating (via a negative phase value) that execution
81 > * is complete.  Termination is triggered when an invocation of {@code
82 > * onAdvance} returns {@code true}.  As illustrated below, when
83 > * phasers control actions with a fixed number of iterations, it is
84 > * often convenient to override this method to cause termination when
85 > * the current phase number reaches a threshold. Method {@link
86 > * #forceTermination} is also available to abruptly release waiting
87 > * threads and allow them to terminate.
88   *
89   * <p> <b>Tiering.</b> Phasers may be <em>tiered</em> (i.e., arranged
90   * in tree structures) to reduce contention. Phasers with large
# Line 97 | Line 97 | import java.util.concurrent.locks.LockSu
97   * <p><b>Monitoring.</b> While synchronization methods may be invoked
98   * only by registered parties, the current state of a phaser may be
99   * monitored by any caller.  At any given moment there are {@link
100 < * #getRegisteredParties}, where {@link #getArrivedParties} have
101 < * arrived at the current phase ({@link #getPhase}). When the
102 < * remaining {@link #getUnarrivedParties}) arrive, the phase
103 < * advances. Method {@link #toString} returns snapshots of these state
104 < * queries in a form convenient for informal monitoring.
100 > * #getRegisteredParties} parties in total, of which {@link
101 > * #getArrivedParties} have arrived at the current phase ({@link
102 > * #getPhase}).  When the remaining ({@link #getUnarrivedParties})
103 > * parties arrive, the phase advances.  The values returned by these
104 > * methods may reflect transient states and so are not in general
105 > * useful for synchronization control.  Method {@link #toString}
106 > * returns snapshots of these state queries in a form convenient for
107 > * informal monitoring.
108   *
109   * <p><b>Sample usages:</b>
110   *
# Line 246 | Line 249 | public class Phaser {
249       */
250      private volatile long state;
251  
249    private static final int ushortBits = 16;
252      private static final int ushortMask = 0xffff;
253      private static final int phaseMask  = 0x7fffffff;
254  
# Line 761 | Line 763 | public class Phaser {
763  
764      /**
765       * Overridable method to perform an action upon phase advance, and
766 <     * to control termination. This method is invoked whenever the
767 <     * barrier is tripped (and thus all other waiting parties are
768 <     * dormant). If it returns {@code true}, then, rather than advance
769 <     * the phase number, this barrier will be set to a final
770 <     * termination state, and subsequent calls to {@link #isTerminated}
771 <     * will return true.
766 >     * to control termination. This method is invoked upon arrival of
767 >     * the party tripping the barrier (when all other waiting parties
768 >     * are dormant).  If this method returns {@code true}, then,
769 >     * rather than advance the phase number, this barrier will be set
770 >     * to a final termination state, and subsequent calls to {@link
771 >     * #isTerminated} will return true. Any (unchecked) Exception or
772 >     * Error thrown by an invocation of this method is propagated to
773 >     * the party attempting to trip the barrier, in which case no
774 >     * advance occurs.
775 >     *
776 >     * <p>The arguments to this method provide the state of the phaser
777 >     * prevailing for the current transition. (When called from within
778 >     * an implementation of {@code onAdvance} the values returned by
779 >     * methods such as {@code getPhase} may or may not reliably
780 >     * indicate the state to which this transition applies.)
781       *
782       * <p>The default version returns {@code true} when the number of
783       * registered parties is zero. Normally, overrides that arrange

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines