Debug Barrier
[IRC.git] / Robust / src / Benchmarks / Prefetch / Moldyn / dsm / DebugBarrier.java
1 public class Barrier {
2   int numthreads;
3   int entercount;
4   boolean cleared;
5
6   public Barrier(int n) {
7       System.printString("Initializing barrier for "+n+" threads.\n");
8     numthreads=n;
9     cleared = false;
10     entercount = 0;
11   }
12
13   public Barrier() {
14   }
15
16   public void reset() {
17     cleared = false;
18     entercount = 0;
19   }
20
21   public static void enterBarrier(Barrier b) {
22     int tmp;
23     boolean retry=true;
24
25     do {
26       atomic {
27           System.printString("Entering barrier with ec="+b.entercount+" cl="+b.cleared+"\n");
28         if (!b.cleared) {
29           b.entercount++;
30           tmp = b.entercount;
31           if (tmp==b.numthreads) {
32             if(b.numthreads > 1)
33               b.cleared=true;
34             b.entercount--;
35             return;
36           }
37           retry=false;
38         }
39       }
40     } while(retry);
41
42     while(true) {
43       atomic {
44         if (b.cleared) {
45           b.entercount--;
46           int count = b.entercount;
47           if (count==0)
48             b.cleared=false;
49           return;
50         }
51       }
52     }
53   }
54 }