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.8 by jsr166, Mon Jul 20 21:54:51 2009 UTC vs.
Revision 1.10 by jsr166, Mon Jul 20 23:07:43 2009 UTC

# Line 153 | Line 153 | public class ForkJoinPool extends Abstra
153  
154      /**
155       * The uncaught exception handler used when any worker
156 <     * abrupty terminates
156 >     * abruptly terminates
157       */
158      private Thread.UncaughtExceptionHandler ueh;
159  
# Line 226 | Line 226 | public class ForkJoinPool extends Abstra
226      private static int workerCountsFor(int t, int r) { return (t << 16) + r; }
227  
228      /**
229 <     * Add delta (which may be negative) to running count.  This must
229 >     * Adds delta (which may be negative) to running count.  This must
230       * be called before (with negative arg) and after (with positive)
231 <     * any managed synchronization (i.e., mainly, joins)
231 >     * any managed synchronization (i.e., mainly, joins).
232       * @param delta the number to add
233       */
234      final void updateRunningCount(int delta) {
# Line 237 | Line 237 | public class ForkJoinPool extends Abstra
237      }
238  
239      /**
240 <     * Add delta (which may be negative) to both total and running
240 >     * Adds delta (which may be negative) to both total and running
241       * count.  This must be called upon creation and termination of
242       * worker threads.
243       * @param delta the number to add
# Line 281 | Line 281 | public class ForkJoinPool extends Abstra
281      }
282  
283      /**
284 <     * Try decrementing active count; fail on contention.
285 <     * Possibly trigger termination on success
284 >     * Tries decrementing active count; fails on contention.
285 >     * Possibly triggers termination on success.
286       * Called by workers when they can't find tasks.
287       * @return true on success
288       */
# Line 297 | Line 297 | public class ForkJoinPool extends Abstra
297      }
298  
299      /**
300 <     * Return true if argument represents zero active count and
300 >     * Returns true if argument represents zero active count and
301       * nonzero runstate, which is the triggering condition for
302       * terminating on shutdown.
303       */
# Line 341 | Line 341 | public class ForkJoinPool extends Abstra
341      }
342  
343      /**
344 <     * Creates a ForkJoinPool with the indicated parellelism level
344 >     * Creates a ForkJoinPool with the indicated parallelism level
345       * threads, and using the default ForkJoinWorkerThreadFactory,
346       * @param parallelism the number of worker threads
347       * @throws IllegalArgumentException if parallelism less than or
# Line 421 | Line 421 | public class ForkJoinPool extends Abstra
421      }
422  
423      /**
424 <     * Return a good size for worker array given pool size.
424 >     * Returns a good size for worker array given pool size.
425       * Currently requires size to be a power of two.
426       */
427      private static int arraySizeFor(int ps) {
# Line 429 | Line 429 | public class ForkJoinPool extends Abstra
429      }
430  
431      /**
432 <     * Create or resize array if necessary to hold newLength.
433 <     * Call only under exlusion or lock
432 >     * Creates or resizes array if necessary to hold newLength.
433 >     * Call only under exclusion or lock.
434       * @return the array
435       */
436      private ForkJoinWorkerThread[] ensureWorkerArrayCapacity(int newLength) {
# Line 716 | Line 716 | public class ForkJoinPool extends Abstra
716  
717  
718      /**
719 <     * Sets the target paralleism level of this pool.
719 >     * Sets the target parallelism level of this pool.
720       * @param parallelism the target parallelism
721       * @throws IllegalArgumentException if parallelism less than or
722       * equal to zero or greater than maximum size bounds.
# Line 819 | Line 819 | public class ForkJoinPool extends Abstra
819       * worker threads only process asynchronous tasks.  This method is
820       * designed to be invoked only when pool is quiescent, and
821       * typically only before any tasks are submitted. The effects of
822 <     * invocations at ather times may be unpredictable.
822 >     * invocations at other times may be unpredictable.
823       *
824       * @param async if true, use locally FIFO scheduling
825       * @return the previous mode.
# Line 973 | Line 973 | public class ForkJoinPool extends Abstra
973       * Removes all available unexecuted submitted and forked tasks
974       * from scheduling queues and adds them to the given collection,
975       * without altering their execution status. These may include
976 <     * artifically generated or wrapped tasks. This method id designed
976 >     * artificially generated or wrapped tasks. This method is designed
977       * to be invoked only when the pool is known to be
978       * quiescent. Invocations at other times may not remove all
979       * tasks. A failure encountered while attempting to add elements
# Line 1183 | Line 1183 | public class ForkJoinPool extends Abstra
1183      }
1184  
1185      /**
1186 <     * Possibly terminate when on shutdown state
1186 >     * Possibly terminates when on shutdown state.
1187       */
1188      private void terminateOnShutdown() {
1189          if (!hasQueuedSubmissions() && canTerminateOnShutdown(runControl))
# Line 1191 | Line 1191 | public class ForkJoinPool extends Abstra
1191      }
1192  
1193      /**
1194 <     * Clear out and cancel submissions
1194 >     * Clears out and cancels submissions.
1195       */
1196      private void cancelQueuedSubmissions() {
1197          ForkJoinTask<?> task;
# Line 1200 | Line 1200 | public class ForkJoinPool extends Abstra
1200      }
1201  
1202      /**
1203 <     * Clean out worker queues.
1203 >     * Cleans out worker queues.
1204       */
1205      private void cancelQueuedWorkerTasks() {
1206          final ReentrantLock lock = this.workerLock;
# Line 1220 | Line 1220 | public class ForkJoinPool extends Abstra
1220      }
1221  
1222      /**
1223 <     * Set each worker's status to terminating. Requires lock to avoid
1224 <     * conflicts with add/remove
1223 >     * Sets each worker's status to terminating. Requires lock to avoid
1224 >     * conflicts with add/remove.
1225       */
1226      private void stopAllWorkers() {
1227          final ReentrantLock lock = this.workerLock;
# Line 1241 | Line 1241 | public class ForkJoinPool extends Abstra
1241      }
1242  
1243      /**
1244 <     * Interrupt all unterminated workers.  This is not required for
1244 >     * Interrupts all unterminated workers.  This is not required for
1245       * sake of internal control, but may help unstick user code during
1246       * shutdown.
1247       */
# Line 1311 | Line 1311 | public class ForkJoinPool extends Abstra
1311          }
1312  
1313          /**
1314 <         * Wake up waiter, returning false if known to already
1314 >         * Wakes up waiter, returning false if known to already
1315           */
1316          boolean signal() {
1317              ForkJoinWorkerThread t = thread;
# Line 1323 | Line 1323 | public class ForkJoinPool extends Abstra
1323          }
1324  
1325          /**
1326 <         * Await release on sync
1326 >         * Awaits release on sync.
1327           */
1328          void awaitSyncRelease(ForkJoinPool p) {
1329              while (thread != null && !p.syncIsReleasable(this))
# Line 1331 | Line 1331 | public class ForkJoinPool extends Abstra
1331          }
1332  
1333          /**
1334 <         * Await resumption as spare
1334 >         * Awaits resumption as spare.
1335           */
1336          void awaitSpareRelease() {
1337              while (thread != null) {
# Line 1371 | Line 1371 | public class ForkJoinPool extends Abstra
1371      }
1372  
1373      /**
1374 <     * Signal threads waiting to poll a task. Because method sync
1374 >     * Signals threads waiting to poll a task. Because method sync
1375       * rechecks availability, it is OK to only proceed if queue
1376       * appears to be non-empty, and OK to skip under contention to
1377       * increment count (since some other thread succeeded).
# Line 1458 | Line 1458 | public class ForkJoinPool extends Abstra
1458      //  Parallelism maintenance
1459  
1460      /**
1461 <     * Decrement running count; if too low, add spare.
1461 >     * Decrements running count; if too low, adds spare.
1462       *
1463       * Conceptually, all we need to do here is add or resume a
1464       * spare thread when one is about to block (and remove or
# Line 1478 | Line 1478 | public class ForkJoinPool extends Abstra
1478       * only be suspended or removed when they are idle, not
1479       * immediately when they aren't needed. So adding threads will
1480       * raise parallelism level for longer than necessary.  Also,
1481 <     * FJ applications often enounter highly transient peaks when
1481 >     * FJ applications often encounter highly transient peaks when
1482       * many threads are blocked joining, but for less time than it
1483       * takes to create or resume spares.
1484       *
# Line 1548 | Line 1548 | public class ForkJoinPool extends Abstra
1548      }
1549  
1550      /**
1551 <     * Add a spare worker if lock available and no more than the
1552 <     * expected numbers of threads exist
1551 >     * Adds a spare worker if lock available and no more than the
1552 >     * expected numbers of threads exist.
1553       * @return true if successful
1554       */
1555      private boolean tryAddSpare(int expectedCounts) {
# Line 1582 | Line 1582 | public class ForkJoinPool extends Abstra
1582      }
1583  
1584      /**
1585 <     * Add the kth spare worker. On entry, pool coounts are already
1585 >     * Adds the kth spare worker. On entry, pool counts are already
1586       * adjusted to reflect addition.
1587       */
1588      private void createAndStartSpare(int k) {
# Line 1604 | Line 1604 | public class ForkJoinPool extends Abstra
1604      }
1605  
1606      /**
1607 <     * Suspend calling thread w if there are excess threads.  Called
1608 <     * only from sync.  Spares are enqueued in a Treiber stack
1609 <     * using the same WaitQueueNodes as barriers.  They are resumed
1610 <     * mainly in preJoin, but are also woken on pool events that
1611 <     * require all threads to check run state.
1607 >     * Suspends calling thread w if there are excess threads.  Called
1608 >     * only from sync.  Spares are enqueued in a Treiber stack using
1609 >     * the same WaitQueueNodes as barriers.  They are resumed mainly
1610 >     * in preJoin, but are also woken on pool events that require all
1611 >     * threads to check run state.
1612       * @param w the caller
1613       */
1614      private boolean suspendIfSpare(ForkJoinWorkerThread w) {
# Line 1629 | Line 1629 | public class ForkJoinPool extends Abstra
1629      }
1630  
1631      /**
1632 <     * Try to pop and resume a spare thread.
1632 >     * Tries to pop and resume a spare thread.
1633       * @param updateCount if true, increment running count on success
1634       * @return true if successful
1635       */
# Line 1647 | Line 1647 | public class ForkJoinPool extends Abstra
1647      }
1648  
1649      /**
1650 <     * Pop and resume all spare threads. Same idea as ensureSync.
1650 >     * Pops and resumes all spare threads. Same idea as ensureSync.
1651       * @return true if any spares released
1652       */
1653      private boolean resumeAllSpares() {
# Line 1665 | Line 1665 | public class ForkJoinPool extends Abstra
1665      }
1666  
1667      /**
1668 <     * Pop and shutdown excessive spare threads. Call only while
1668 >     * Pops and shuts down excessive spare threads. Call only while
1669       * holding lock. This is not guaranteed to eliminate all excess
1670       * threads, only those suspended as spares, which are the ones
1671       * unlikely to be needed in the future.
# Line 1719 | Line 1719 | public class ForkJoinPool extends Abstra
1719           * @return true if no additional blocking is necessary (i.e.,
1720           * if isReleasable would return true).
1721           * @throws InterruptedException if interrupted while waiting
1722 <         * (the method is not required to do so, but is allowe to).
1722 >         * (the method is not required to do so, but is allowed to).
1723           */
1724          boolean block() throws InterruptedException;
1725  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines