projects
/
IRC.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
add our barrier
[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;
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
}
35
retry=false;
36
}
37
}
38
} while(retry);
39
40
while(true) {
41
atomic {
42
if (b.cleared) {
43
b.entercount--;
44
int count = b.entercount;
45
if (count==0)
46
b.cleared=false;
47
return;
48
}
49
}
50
}
51
}
52
}