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

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.66 by dl, Sun Aug 29 23:34:46 2010 UTC vs.
Revision 1.69 by jsr166, Wed Sep 1 20:12:39 2010 UTC

# Line 69 | Line 69 | import java.util.concurrent.CountDownLat
69   *    <td ALIGN=CENTER> <b>Call from within fork/join computations</b></td>
70   *  </tr>
71   *  <tr>
72 < *    <td> <b>Arange async execution</td>
72 > *    <td> <b>Arrange async execution</td>
73   *    <td> {@link #execute(ForkJoinTask)}</td>
74   *    <td> {@link ForkJoinTask#fork}</td>
75   *  </tr>
# Line 140 | Line 140 | public class ForkJoinPool extends Abstra
140       * Beyond work-stealing support and essential bookkeeping, the
141       * main responsibility of this framework is to take actions when
142       * one worker is waiting to join a task stolen (or always held by)
143 <     * another.  Becauae we are multiplexing many tasks on to a pool
143 >     * another.  Because we are multiplexing many tasks on to a pool
144       * of workers, we can't just let them block (as in Thread.join).
145       * We also cannot just reassign the joiner's run-time stack with
146       * another and replace it later, which would be a form of
# Line 157 | Line 157 | public class ForkJoinPool extends Abstra
157       *      links to try to find such a task.
158       *
159       *   Compensating: Unless there are already enough live threads,
160 <     *      method helpMaintainParallelism() may create or or
160 >     *      method helpMaintainParallelism() may create or
161       *      re-activate a spare thread to compensate for blocked
162       *      joiners until they unblock.
163       *
# Line 226 | Line 226 | public class ForkJoinPool extends Abstra
226       * ManagedBlocker), we may create or resume others to take their
227       * place until they unblock (see below). Implementing this
228       * requires counts of the number of "running" threads (i.e., those
229 <     * that are neither blocked nor artifically suspended) as well as
229 >     * that are neither blocked nor artificially suspended) as well as
230       * the total number.  These two values are packed into one field,
231       * "workerCounts" because we need accurate snapshots when deciding
232       * to create, resume or suspend.  Note however that the
233 <     * correspondance of these counts to reality is not guaranteed. In
233 >     * correspondence of these counts to reality is not guaranteed. In
234       * particular updates for unblocked threads may lag until they
235       * actually wake up.
236       *
# Line 315 | Line 315 | public class ForkJoinPool extends Abstra
315       * 7. Deciding when to create new workers. The main dynamic
316       * control in this class is deciding when to create extra threads
317       * in method helpMaintainParallelism. We would like to keep
318 <     * exactly #parallelism threads running, which is an impossble
318 >     * exactly #parallelism threads running, which is an impossible
319       * task. We always need to create one when the number of running
320       * threads would become zero and all workers are busy. Beyond
321 <     * this, we must rely on heuristics that work well in the the
322 <     * presence of transients phenomena such as GC stalls, dynamic
321 >     * this, we must rely on heuristics that work well in the
322 >     * presence of transient phenomena such as GC stalls, dynamic
323       * compilation, and wake-up lags. These transients are extremely
324       * common -- we are normally trying to fully saturate the CPUs on
325       * a machine, so almost any activity other than running tasks
# Line 346 | Line 346 | public class ForkJoinPool extends Abstra
346       * "while ((local = field) != 0)") which are usually the simplest
347       * way to ensure the required read orderings (which are sometimes
348       * critical). Also several occurrences of the unusual "do {}
349 <     * while(!cas...)" which is the simplest way to force an update of
349 >     * while (!cas...)" which is the simplest way to force an update of
350       * a CAS'ed variable. There are also other coding oddities that
351       * help some methods perform reasonably even when interpreted (not
352       * compiled), at the expense of some messy constructions that
# Line 420 | Line 420 | public class ForkJoinPool extends Abstra
420      /**
421       * The time to block in a join (see awaitJoin) before checking if
422       * a new worker should be (re)started to maintain parallelism
423 <     * level. The value should be short enough to maintain gloabal
423 >     * level. The value should be short enough to maintain global
424       * responsiveness and progress but long enough to avoid
425       * counterproductive firings during GC stalls or unrelated system
426       * activity, and to not bog down systems with continual re-firings
# Line 483 | Line 483 | public class ForkJoinPool extends Abstra
483      private volatile long stealCount;
484  
485      /**
486 <     * Encoded record of top of treiber stack of threads waiting for
486 >     * Encoded record of top of Treiber stack of threads waiting for
487       * events. The top 32 bits contain the count being waited for. The
488       * bottom 16 bits contains one plus the pool index of waiting
489       * worker thread. (Bits 16-31 are unused.)
# Line 502 | Line 502 | public class ForkJoinPool extends Abstra
502      private volatile int eventCount;
503  
504      /**
505 <     * Encoded record of top of treiber stack of spare threads waiting
505 >     * Encoded record of top of Treiber stack of spare threads waiting
506       * for resumption. The top 16 bits contain an arbitrary count to
507       * avoid ABA effects. The bottom 16bits contains one plus the pool
508       * index of waiting worker thread.
# Line 678 | Line 678 | public class ForkJoinPool extends Abstra
678       */
679      private void forgetWorker(ForkJoinWorkerThread w) {
680          int idx = w.poolIndex;
681 <        // Locking helps method recordWorker avoid unecessary expansion
681 >        // Locking helps method recordWorker avoid unnecessary expansion
682          final ReentrantLock lock = this.workerLock;
683          lock.lock();
684          try {
# Line 693 | Line 693 | public class ForkJoinPool extends Abstra
693      /**
694       * Final callback from terminating worker.  Removes record of
695       * worker from array, and adjusts counts. If pool is shutting
696 <     * down, tries to complete terminatation.
696 >     * down, tries to complete termination.
697       *
698       * @param w the worker
699       */
# Line 832 | Line 832 | public class ForkJoinPool extends Abstra
832              UNSAFE.compareAndSwapInt(this, spareWaitersOffset,
833                                       sw, w.nextSpare)) {
834              int c; // increment running count before resume
835 <            do {} while(!UNSAFE.compareAndSwapInt
836 <                        (this, workerCountsOffset,
837 <                         c = workerCounts, c + ONE_RUNNING));
835 >            do {} while (!UNSAFE.compareAndSwapInt
836 >                         (this, workerCountsOffset,
837 >                          c = workerCounts, c + ONE_RUNNING));
838              if (w.tryUnsuspend())
839                  LockSupport.unpark(w);
840              else   // back out if w was shutdown
# Line 846 | Line 846 | public class ForkJoinPool extends Abstra
846       * Tries to increase the number of running workers if below target
847       * parallelism: If a spare exists tries to resume it via
848       * tryResumeSpare.  Otherwise, if not enough total workers or all
849 <     * existing workers are busy, adds a new worker. In all casses also
849 >     * existing workers are busy, adds a new worker. In all cases also
850       * helps wake up releasable workers waiting for work.
851       */
852      private void helpMaintainParallelism() {
# Line 985 | Line 985 | public class ForkJoinPool extends Abstra
985                      w.lastEventCount = ec;     // no need to wait
986                      break;
987                  }
988 <                else if (!(inactivate |= active))  
988 >                else if (!(inactivate |= active))
989                      eventSync(w, wec);         // must inactivate before sync
990              }
991              else
# Line 1174 | Line 1174 | public class ForkJoinPool extends Abstra
1174       */
1175      final int idlePerActive() {
1176          int pc = parallelism; // use parallelism, not rc
1177 <        int ac = runState;    // no mask -- artifically boosts during shutdown
1177 >        int ac = runState;    // no mask -- artificially boosts during shutdown
1178          // Use exact results for small values, saturate past 4
1179          return pc <= ac? 0 : pc >>> 1 <= ac? 1 : pc >>> 2 <= ac? 3 : pc >>> 3;
1180      }
# Line 1721 | Line 1721 | public class ForkJoinPool extends Abstra
1721          throws InterruptedException {
1722          try {
1723              return termination.awaitAdvanceInterruptibly(0, timeout, unit) > 0;
1724 <        } catch(TimeoutException ex) {
1724 >        } catch (TimeoutException ex) {
1725              return false;
1726          }
1727      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines