153 |
|
|
154 |
|
/** |
155 |
|
* The uncaught exception handler used when any worker |
156 |
< |
* abrupty terminates |
156 |
> |
* abruptly terminates |
157 |
|
*/ |
158 |
|
private Thread.UncaughtExceptionHandler ueh; |
159 |
|
|
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) { |
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 |
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 |
|
*/ |
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 |
|
*/ |
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 |
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) { |
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) { |
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. |
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. |
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 |
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)) |
1191 |
|
} |
1192 |
|
|
1193 |
|
/** |
1194 |
< |
* Clear out and cancel submissions |
1194 |
> |
* Clears out and cancels submissions. |
1195 |
|
*/ |
1196 |
|
private void cancelQueuedSubmissions() { |
1197 |
|
ForkJoinTask<?> task; |
1200 |
|
} |
1201 |
|
|
1202 |
|
/** |
1203 |
< |
* Clean out worker queues. |
1203 |
> |
* Cleans out worker queues. |
1204 |
|
*/ |
1205 |
|
private void cancelQueuedWorkerTasks() { |
1206 |
|
final ReentrantLock lock = this.workerLock; |
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; |
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 |
|
*/ |
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; |
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)) |
1331 |
|
} |
1332 |
|
|
1333 |
|
/** |
1334 |
< |
* Await resumption as spare |
1334 |
> |
* Awaits resumption as spare. |
1335 |
|
*/ |
1336 |
|
void awaitSpareRelease() { |
1337 |
|
while (thread != null) { |
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). |
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 |
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 |
|
* |
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) { |
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) { |
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) { |
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 |
|
*/ |
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() { |
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. |
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 |
|
|