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.*; |
7 |
|
import java.util.*; |
8 |
+ |
import java.util.concurrent.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
|
|
11 |
|
public final class AsyncNQueensCS extends LinkedAsyncAction { |
23 |
|
|
24 |
|
/** for time conversion */ |
25 |
|
static final long NPS = (1000L * 1000 * 1000); |
26 |
< |
|
26 |
> |
|
27 |
|
public static void main(String[] args) throws Exception { |
28 |
|
int procs = 0; |
29 |
|
try { |
35 |
|
return; |
36 |
|
} |
37 |
|
for (int reps = 0; reps < 2; ++reps) { |
38 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
38 |
> |
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : |
39 |
|
new ForkJoinPool(procs); |
40 |
|
System.out.println("Number of procs=" + g.getParallelism()); |
41 |
|
lastStealCount = g.getStealCount(); |
42 |
|
for (int i = FIRST_SIZE; i <= LAST_SIZE; i++) |
43 |
|
test(g, i); |
44 |
< |
g.shutdown(); |
44 |
> |
g.shutdown(); |
45 |
|
} |
46 |
|
} |
47 |
|
|
63 |
|
lastStealCount = sc; |
64 |
|
System.out.printf(" Steals/t: %5d", ns/ps); |
65 |
|
System.out.println(); |
66 |
< |
} |
66 |
> |
} |
67 |
|
|
68 |
< |
// Boards are represented as arrays where each cell |
68 |
> |
// Boards are represented as arrays where each cell |
69 |
|
// holds the column number of the queen in that row |
70 |
|
|
71 |
|
final int[] sofar; |
72 |
|
volatile int solutions; |
73 |
< |
AsyncNQueensCS(AsyncNQueensCS parent, int[] a) { |
73 |
> |
AsyncNQueensCS(AsyncNQueensCS parent, int[] a) { |
74 |
|
super(parent); |
75 |
< |
this.sofar = a; |
75 |
> |
this.sofar = a; |
76 |
|
} |
77 |
|
|
78 |
|
public final boolean exec() { |
106 |
|
|
107 |
|
static final AtomicIntegerFieldUpdater<AsyncNQueensCS> solutionUpdater = |
108 |
|
AtomicIntegerFieldUpdater.newUpdater(AsyncNQueensCS.class, "solutions"); |
109 |
– |
|
110 |
– |
|
109 |
|
} |