-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
63 lines (58 loc) · 1.33 KB
/
Example.java
File metadata and controls
63 lines (58 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//Generated by Tiddle, UC Santa Cruz
/*
rd 1 x
wr 2 x
*/
package mypackage;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class Example {
static int x = 0;
static CyclicBarrier cb = new CyclicBarrier(2);
static CyclicBarrier cc = new CyclicBarrier(2);
static int counter = 0;
static int numThreads = 2;
static public void await(CyclicBarrier c) throws BrokenBarrierException, InterruptedException {
c.await();
}
public static void main(String[] args) {
final Thread t2 = new Thread() {
public void run() {
try {
int _z = 0;
await(cc);
await(cb);
await(cc);
x = 1;
await(cb);
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (BrokenBarrierException e) {
e.printStackTrace();
}
}
};
final Thread t1 = new Thread() {
public void run() {
try {
int _z = 0;
await(cc);
_z = x;
await(cb);
await(cc);
await(cb);
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (BrokenBarrierException e) {
e.printStackTrace();
}
}
};
t1.start();
t2.start();
}
}