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.*; |
17 |
|
static int replications = 20; |
18 |
|
|
19 |
|
public static void main(String[] args) throws Exception { |
20 |
< |
if (args.length > 0) |
20 |
> |
if (args.length > 0) |
21 |
|
replications = Integer.parseInt(args[0]); |
22 |
|
|
23 |
< |
if (args.length > 1) |
23 |
> |
if (args.length > 1) |
24 |
|
nlocks = Integer.parseInt(args[1]); |
25 |
|
|
26 |
|
print = true; |
48 |
|
} |
49 |
|
|
50 |
|
final void test() throws Exception { |
51 |
< |
for (int i = 0; i < nthreads; ++i) |
51 |
> |
for (int i = 0; i < nthreads; ++i) |
52 |
|
pool.execute(this); |
53 |
|
barrier.await(); |
54 |
|
barrier.await(); |
55 |
|
if (print) { |
56 |
|
long time = timer.getTime(); |
57 |
< |
double secs = (double)(time) / 1000000000.0; |
57 |
> |
double secs = (double) time / 1000000000.0; |
58 |
|
System.out.println("\t " + secs + "s run time"); |
59 |
|
} |
60 |
|
|
65 |
|
|
66 |
|
public final void run() { |
67 |
|
try { |
68 |
< |
barrier.await(); |
68 |
> |
barrier.await(); |
69 |
|
int sum = v; |
70 |
|
int x = 0; |
71 |
|
for (int i = 0; i < locks.length; ++i) { |
86 |
|
barrier.await(); |
87 |
|
result += sum; |
88 |
|
} |
89 |
< |
catch (Exception ie) { |
90 |
< |
return; |
89 |
> |
catch (Exception ie) { |
90 |
> |
return; |
91 |
|
} |
92 |
|
} |
93 |
|
} |