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.42 by dl, Mon Aug 24 18:37:15 2009 UTC vs.
Revision 1.44 by dl, Tue Aug 25 16:32:28 2009 UTC

# Line 188 | Line 188 | import java.util.concurrent.locks.LockSu
188   * Task class with a constructor accepting a phaser that
189   * it registers for upon construction:
190   *  <pre> {@code
191 < * void build(Task[] actions, int lo, int hi, Phaser b) {
192 < *   int step = (hi - lo) / TASKS_PER_PHASER;
193 < *   if (step > 1) {
194 < *     int i = lo;
195 < *     while (i < hi) {
196 < *       int r = Math.min(i + step, hi);
197 < *       build(actions, i, r, new Phaser(b));
198 < *       i = r;
191 > * void build(Task[] actions, int lo, int hi, Phaser ph) {
192 > *   if (hi - lo > TASKS_PER_PHASER) {
193 > *     for (int i = lo; i < hi; i += TASKS_PER_PHASER) {
194 > *       int j = Math.min(i + TASKS_PER_PHASER, hi);
195 > *       build(actions, i, j, new Phaser(ph));
196   *     }
197   *   } else {
198   *     for (int i = lo; i < hi; ++i)
199 < *       actions[i] = new Task(b);
200 < *       // assumes new Task(b) performs b.register()
199 > *       actions[i] = new Task(ph);
200 > *       // assumes new Task(ph) performs ph.register()
201   *   }
202   * }
203   * // .. initially called, for n tasks via
# Line 762 | Line 759 | public class Phaser {
759      }
760  
761      /**
762 <     * Overridable method to perform an action upon phase advance, and
763 <     * to control termination. This method is invoked upon arrival of
764 <     * the party tripping the barrier (when all other waiting parties
765 <     * are dormant).  If this method returns {@code true}, then,
766 <     * rather than advance the phase number, this barrier will be set
767 <     * to a final termination state, and subsequent calls to {@link
768 <     * #isTerminated} will return true. Any (unchecked) Exception or
769 <     * Error thrown by an invocation of this method is propagated to
770 <     * the party attempting to trip the barrier, in which case no
771 <     * advance occurs.
762 >     * Overridable method to perform an action upon impending phase
763 >     * advance, and to control termination. This method is invoked
764 >     * upon arrival of the party tripping the barrier (when all other
765 >     * waiting parties are dormant).  If this method returns {@code
766 >     * true}, then, rather than advance the phase number, this barrier
767 >     * will be set to a final termination state, and subsequent calls
768 >     * to {@link #isTerminated} will return true. Any (unchecked)
769 >     * Exception or Error thrown by an invocation of this method is
770 >     * propagated to the party attempting to trip the barrier, in
771 >     * which case no advance occurs.
772       *
773       * <p>The arguments to this method provide the state of the phaser
774       * prevailing for the current transition. (When called from within
# Line 785 | Line 782 | public class Phaser {
782       * property.
783       *
784       * <p>You may override this method to perform an action with side
785 <     * effects visible to participating tasks, but it is in general
786 <     * only sensible to do so in designs where all parties register
787 <     * before any arrive, and all {@link #awaitAdvance} at each phase.
788 <     * Otherwise, you cannot ensure lack of interference from other
789 <     * parties during the invocation of this method.
785 >     * effects visible to participating tasks, but doing so requires
786 >     * care: Method {@code onAdvance} may be invoked more than once
787 >     * per transition.  Further, unless all parties register before
788 >     * any arrive, and all {@link #awaitAdvance} at each phase, then
789 >     * you cannot ensure lack of interference from other parties
790 >     * during the invocation of this method.
791       *
792       * @param phase the phase number on entering the barrier
793       * @param registeredParties the current number of registered parties

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines