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 |
|
import java.util.concurrent.*; |
8 |
|
|
9 |
< |
public final class DynamicAsyncFib extends BinaryAsyncAction { |
9 |
> |
public final class DynamicAsyncFib extends BinaryAsyncAction { |
10 |
|
int number; |
11 |
|
|
12 |
|
public DynamicAsyncFib(int n) { |
17 |
|
DynamicAsyncFib f = this; |
18 |
|
int n = f.number; |
19 |
|
while (n > 1 && getSurplusQueuedTaskCount() <= 3) { |
20 |
< |
DynamicAsyncFib l = new DynamicAsyncFib(--n); |
21 |
< |
DynamicAsyncFib r = new DynamicAsyncFib(n - 1); |
20 |
> |
DynamicAsyncFib l = new DynamicAsyncFib(n - 1); |
21 |
> |
DynamicAsyncFib r = new DynamicAsyncFib(n - 2); |
22 |
|
f.linkSubtasks(l, r); |
23 |
|
r.fork(); |
24 |
|
f = l; |
25 |
+ |
--n; |
26 |
|
} |
27 |
< |
f.number = seqFib(n); |
27 |
> |
f.number = n <= 1? n : seqFib(n); |
28 |
|
f.complete(); |
29 |
|
return false; |
30 |
|
} |
50 |
|
} |
51 |
|
|
52 |
|
for (int reps = 0; reps < 2; ++reps) { |
53 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
53 |
> |
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : |
54 |
|
new ForkJoinPool(procs); |
55 |
|
lastStealCount = g.getStealCount(); |
56 |
|
for (int i = 0; i < 20; ++i) { |
93 |
|
return r; |
94 |
|
} |
95 |
|
} |
95 |
– |
|
96 |
– |
|