Add Test for multicore gc version 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 synchronized void add(long value){
10     this.count += value;
11     System.printString(" " + this.count + "\n");
12   }
13   
14   public synchronized long getCounter() {
15     return this.count;
16   }
17 }
18
19 public class CounterThread extends Thread{
20
21   String name;
22   protected Counter counter;
23
24   public CounterThread(String name, Counter counter){
25     this.name = name;
26     this.counter = counter;
27   }
28
29   public void run() {
30     for(int i=0; i<10; i++){
31       System.printString(this.name);
32       counter.add(i);
33     }
34   }
35 }
36
37 public class SynchonizedTest {
38   public SynchonizedTest() {
39   }
40
41   public static void main(String[] args){
42     Counter counter = new Counter();
43     Thread  threadA = new CounterThread("A\n",counter);
44     Thread  threadB = new CounterThread("B\n",counter);
45
46     threadA.start();
47     threadB.start(); 
48   }
49 }