Small bug fix for multicore gc w/o tasks
[IRC.git] / Robust / src / Tests / MGC / SynchonizedTest.java
1 public class Counter{
2      
3   long count;
4   
5   public Counter() {
6     this.count = 0;
7   }
8
9   public add(long value){
10         synchronized (this) {
11       this.count += value;
12         }
13   }
14   
15   public synchronized long getCounter() {
16     return this.count;
17   }
18 }
19
20 public class CounterThread extends Thread{
21
22   String name;
23   protected Counter counter;
24
25   public CounterThread(String name, Counter counter){
26     this.name = name;
27     this.counter = counter;
28   }
29
30   public void run() {
31     for(int i=0; i<10; i++){
32       System.printString(this.name);
33       counter.add(i);
34       System.printString(" " + counter.getCounter() + "\n");
35     }
36   }
37 }
38
39 public class SynchonizedTest {
40   public SynchonizedTest() {
41   }
42
43   public static void main(String[] args){
44     Counter counter = new Counter();
45     Thread  threadA = new CounterThread("A\n",counter);
46     Thread  threadB = new CounterThread("B\n",counter);
47
48     threadA.start();
49     threadB.start(); 
50   }
51   
52   /*public static void main(String[] args){
53     Counter counterA = new Counter();
54     Counter counterB = new Counter();
55     Thread  threadA = new CounterThread("A\n",counterA);
56     Thread  threadB = new CounterThread("B\n",counterB);
57
58     threadA.start();
59     threadB.start(); 
60   }*/
61 }