1 |
|
/* |
2 |
– |
* @test |
3 |
– |
* @summary Checks for missed signals by locking and unlocking each of an array of locks once per thread |
4 |
– |
*/ |
5 |
– |
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
< |
* Expert Group and released to the public domain. Use, modify, and |
4 |
< |
* redistribute this code in any way without acknowledgement. |
3 |
> |
* Expert Group and released to the public domain, as explained at |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import java.util.concurrent.*; |
8 |
< |
import java.util.concurrent.locks.*; |
9 |
< |
import java.util.*; |
7 |
> |
import java.util.concurrent.CyclicBarrier; |
8 |
> |
import java.util.concurrent.ExecutorService; |
9 |
> |
import java.util.concurrent.Executors; |
10 |
> |
import java.util.concurrent.locks.ReentrantLock; |
11 |
|
|
12 |
|
public final class LockOncePerThreadLoops { |
13 |
|
static final ExecutorService pool = Executors.newCachedThreadPool(); |
18 |
|
static int replications = 20; |
19 |
|
|
20 |
|
public static void main(String[] args) throws Exception { |
21 |
< |
if (args.length > 0) |
21 |
> |
if (args.length > 0) |
22 |
|
replications = Integer.parseInt(args[0]); |
23 |
|
|
24 |
< |
if (args.length > 1) |
24 |
> |
if (args.length > 1) |
25 |
|
nlocks = Integer.parseInt(args[1]); |
26 |
|
|
27 |
|
print = true; |
49 |
|
} |
50 |
|
|
51 |
|
final void test() throws Exception { |
52 |
< |
for (int i = 0; i < nthreads; ++i) |
52 |
> |
for (int i = 0; i < nthreads; ++i) |
53 |
|
pool.execute(this); |
54 |
|
barrier.await(); |
55 |
|
barrier.await(); |
56 |
|
if (print) { |
57 |
|
long time = timer.getTime(); |
58 |
< |
double secs = (double)(time) / 1000000000.0; |
58 |
> |
double secs = (double) time / 1000000000.0; |
59 |
|
System.out.println("\t " + secs + "s run time"); |
60 |
|
} |
61 |
|
|
66 |
|
|
67 |
|
public final void run() { |
68 |
|
try { |
69 |
< |
barrier.await(); |
69 |
> |
barrier.await(); |
70 |
|
int sum = v; |
71 |
|
int x = 0; |
72 |
|
for (int i = 0; i < locks.length; ++i) { |
87 |
|
barrier.await(); |
88 |
|
result += sum; |
89 |
|
} |
90 |
< |
catch (Exception ie) { |
91 |
< |
return; |
90 |
> |
catch (Exception ie) { |
91 |
> |
return; |
92 |
|
} |
93 |
|
} |
94 |
|
} |