projects
/
IRC.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
adding a test case
[IRC.git]
/
Robust
/
src
/
Benchmarks
/
Prefetch
/
Moldyn
/
dsm
/
Barrier.java
1
public class Barrier {
2
int numthreads;
3
int entercount;
4
boolean cleared;
5
6
public Barrier(int n) {
7
numthreads=n;
8
cleared = false;
9
entercount = 0;
10
}
11
12
public Barrier() {
13
}
14
15
public void reset() {
16
cleared = false;
17
entercount = 0;
18
}
19
20
public static void enterBarrier(Barrier b) {
21
int tmp;
22
boolean retry=true, ret1=false, ret2=true;;
23
24
do {
25
atomic {
26
if (!b.cleared) {
27
b.entercount++;
28
tmp = b.entercount;
29
if (tmp==b.numthreads) {
30
if(b.numthreads > 1)
31
b.cleared=true;
32
b.entercount--;
33
//return;
34
ret1 = true;
35
}
36
retry=false;
37
}
38
}
39
} while(retry);
40
if (ret1) return;
41
while(ret2) {
42
atomic {
43
if (b.cleared) {
44
b.entercount--;
45
int count = b.entercount;
46
if (count==0)
47
b.cleared=false;
48
//return;
49
ret2=false;
50
}
51
}
52
}
53
}
54
}