1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166y; |
10 |
|
* A recursive resultless {@link ForkJoinTask}. This class |
11 |
|
* establishes conventions to parameterize resultless actions as |
12 |
|
* {@code Void} {@code ForkJoinTask}s. Because {@code null} is the |
13 |
< |
* only valid value of type {@code Void}, methods such as join always |
14 |
< |
* return {@code null} upon completion. |
13 |
> |
* only valid value of type {@code Void}, methods such as {@code join} |
14 |
> |
* always return {@code null} upon completion. |
15 |
|
* |
16 |
|
* <p><b>Sample Usages.</b> Here is a sketch of a ForkJoin sort that |
17 |
|
* sorts a given {@code long[]} array: |
18 |
|
* |
19 |
|
* <pre> {@code |
20 |
|
* class SortTask extends RecursiveAction { |
21 |
< |
* final long[] array; final int lo; final int hi; |
21 |
> |
* final long[] array; final int lo, hi; |
22 |
|
* SortTask(long[] array, int lo, int hi) { |
23 |
|
* this.array = array; this.lo = lo; this.hi = hi; |
24 |
|
* } |
29 |
|
* int mid = (lo + hi) >>> 1; |
30 |
|
* invokeAll(new SortTask(array, lo, mid), |
31 |
|
* new SortTask(array, mid, hi)); |
32 |
< |
* merge(array, lo, hi); |
32 |
> |
* merge(array, lo, mid, hi); |
33 |
|
* } |
34 |
|
* } |
35 |
|
* }}</pre> |
36 |
|
* |
37 |
|
* You could then sort {@code anArray} by creating {@code new |
38 |
< |
* SortTask(anArray, 0, anArray.length-1) } and invoking it in a |
38 |
> |
* SortTask(anArray, 0, anArray.length) } and invoking it in a |
39 |
|
* ForkJoinPool. As a more concrete simple example, the following |
40 |
|
* task increments each element of an array: |
41 |
|
* <pre> {@code |
42 |
|
* class IncrementTask extends RecursiveAction { |
43 |
< |
* final long[] array; final int lo; final int hi; |
43 |
> |
* final long[] array; final int lo, hi; |
44 |
|
* IncrementTask(long[] array, int lo, int hi) { |
45 |
|
* this.array = array; this.lo = lo; this.hi = hi; |
46 |
|
* } |
109 |
|
* if (right.tryUnfork()) // directly calculate if not stolen |
110 |
|
* sum += right.atLeaf(right.lo, right.hi); |
111 |
|
* else { |
112 |
< |
* right.helpJoin(); |
112 |
> |
* right.join(); |
113 |
|
* sum += right.result; |
114 |
|
* } |
115 |
|
* right = right.next; |
130 |
|
protected abstract void compute(); |
131 |
|
|
132 |
|
/** |
133 |
< |
* Always returns null. |
133 |
> |
* Always returns {@code null}. |
134 |
> |
* |
135 |
> |
* @return {@code null} always |
136 |
|
*/ |
137 |
|
public final Void getRawResult() { return null; } |
138 |
|
|