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.39 by dl, Mon Aug 24 12:15:46 2009 UTC vs.
Revision 1.43 by dl, Mon Aug 24 23:08:18 2009 UTC

# 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 760 | Line 762 | public class Phaser {
762      }
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.
765 >     * Overridable method to perform an action upon impending phase
766 >     * advance, and to control termination. This method is invoked
767 >     * upon arrival of the party tripping the barrier (when all other
768 >     * waiting parties are dormant).  If this method returns {@code
769 >     * true}, then, rather than advance the phase number, this barrier
770 >     * will be set to a final termination state, and subsequent calls
771 >     * to {@link #isTerminated} will return true. Any (unchecked)
772 >     * Exception or Error thrown by an invocation of this method is
773 >     * propagated to the party attempting to trip the barrier, in
774 >     * which case no 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
# Line 774 | Line 785 | public class Phaser {
785       * property.
786       *
787       * <p>You may override this method to perform an action with side
788 <     * effects visible to participating tasks, but it is in general
789 <     * only sensible to do so in designs where all parties register
790 <     * before any arrive, and all {@link #awaitAdvance} at each phase.
791 <     * Otherwise, you cannot ensure lack of interference from other
792 <     * parties during the invocation of this method.
788 >     * effects visible to participating tasks, but doing so requires
789 >     * care: Method {@code onAdvance} may be invoked more than once
790 >     * per transition.  Further, unless all parties register before
791 >     * any arrive, and all {@link #awaitAdvance} at each phase, then
792 >     * you cannot ensure lack of interference from other parties
793 >     * during the invocation of this method.
794       *
795       * @param phase the phase number on entering the barrier
796       * @param registeredParties the current number of registered parties

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines