helpful progress reporting
[IRC.git] / Robust / src / Benchmarks / Prefetch / MicroBenchmarks / Simple.java
1 public class Simple extends Thread {
2   Counting mycount;
3   public Simple(Counting mycount) {
4     this.mycount = mycount;
5   }
6
7   public void run() {
8     for(int i = 0;  i < 10000; i++) {
9       atomic {
10         mycount.increment();
11       }
12     }
13   }
14
15   public static void main(String[] args) {
16     Simple[] s;
17     Counting c;
18     int numthreads = 2;
19     int[] mid = new int[2];
20         mid[0] = (128<<24)|(195<<16)|(175<<8)|79; //dw-8
21         mid[1] = (128<<24)|(195<<16)|(175<<8)|73; //dw-5
22     atomic {
23       c = global new Counting();
24       s = global new Simple[numthreads];
25       for(int i = 0; i < 2; i++) {
26         s[i] = global new Simple(c);
27       }
28     }
29
30     Simple tmp;
31     for(int i = 0; i <  2; i++) {
32       atomic {
33         tmp = s[i];
34       }
35       tmp.start(mid[i]);
36     }
37
38     for(int i = 0; i < 2; i++) {
39       atomic {
40         tmp = s[i];
41       }
42       tmp.join();
43     }
44     //print count
45     int finalcount;
46     atomic {
47       finalcount = c.count;
48     }
49     System.printString("Count = "+finalcount+"\n");
50   }
51
52 }
53
54 class Counting {
55   global int count;
56   public Counting() {
57     this.count = 0;
58   }
59
60   public increment() {
61     count = count + 1;
62   }
63 }