126 |
|
* op.apply(array[lo]); |
127 |
|
* tryComplete(); |
128 |
|
* } |
129 |
< |
* } }</pre> |
129 |
> |
* }}</pre> |
130 |
|
* |
131 |
|
* This design can be improved by noticing that in the recursive case, |
132 |
|
* the task has nothing to do after forking its right task, so can |
133 |
|
* directly invoke its left task before returning. (This is an analog |
134 |
|
* of tail recursion removal.) Also, because the task returns upon |
135 |
|
* executing its left task (rather than falling through to invoke |
136 |
< |
* tryComplete) the pending count is set to one: |
136 |
> |
* {@code tryComplete}) the pending count is set to one: |
137 |
|
* |
138 |
|
* <pre> {@code |
139 |
|
* class ForEach<E> ... |
291 |
|
* return new MapReducer<E>(null, array, mapper, reducer, |
292 |
|
* 0, array.length).invoke(); |
293 |
|
* } |
294 |
< |
* } }</pre> |
294 |
> |
* }}</pre> |
295 |
|
* |
296 |
|
* Here, method {@code onCompletion} takes a form common to many |
297 |
|
* completion designs that combine results. This callback-style method |
303 |
|
* distinguishes cases. Most often, when the caller is {@code this}, |
304 |
|
* no action is necessary. Otherwise the caller argument can be used |
305 |
|
* (usually via a cast) to supply a value (and/or links to other |
306 |
< |
* values) to be combined. Asuuming proper use of pending counts, the |
306 |
> |
* values) to be combined. Assuming proper use of pending counts, the |
307 |
|
* actions inside {@code onCompletion} occur (once) upon completion of |
308 |
|
* a task and its subtasks. No additional synchronization is required |
309 |
|
* within this method to ensure thread safety of accesses to fields of |
626 |
|
* this task's pending count is non-zero, decrements its pending |
627 |
|
* count and returns {@code null}. Otherwise, returns the |
628 |
|
* completer. This method can be used as part of a completion |
629 |
< |
* traversal loop for homogenous task hierarchies: |
629 |
> |
* traversal loop for homogeneous task hierarchies: |
630 |
|
* |
631 |
|
* <pre> {@code |
632 |
< |
* for (CountedCompleter<?> c = firstComplete(); c != null; c = c.nextComplete()) { |
632 |
> |
* for (CountedCompleter<?> c = firstComplete(); |
633 |
> |
* c != null; |
634 |
> |
* c = c.nextComplete()) { |
635 |
|
* // ... process c ... |
636 |
|
* }}</pre> |
637 |
|
* |
661 |
|
} |
662 |
|
|
663 |
|
/** |
664 |
< |
* Support for FJT exception propagation |
664 |
> |
* Supports ForkJoinTask exception propagation. |
665 |
|
*/ |
666 |
|
void internalPropagateException(Throwable ex) { |
667 |
|
CountedCompleter<?> a = this, s = a; |
671 |
|
} |
672 |
|
|
673 |
|
/** |
674 |
< |
* Implements execution conventions for CountedCompleters |
674 |
> |
* Implements execution conventions for CountedCompleters. |
675 |
|
*/ |
676 |
|
protected final boolean exec() { |
677 |
|
compute(); |