Add Test for multicore gc version w/o tasks
authorjzhou <jzhou>
Thu, 14 Oct 2010 17:59:34 +0000 (17:59 +0000)
committerjzhou <jzhou>
Thu, 14 Oct 2010 17:59:34 +0000 (17:59 +0000)
Robust/src/Tests/MGC/SynchonizedTest.java [new file with mode: 0644]

diff --git a/Robust/src/Tests/MGC/SynchonizedTest.java b/Robust/src/Tests/MGC/SynchonizedTest.java
new file mode 100644 (file)
index 0000000..bb63fb1
--- /dev/null
@@ -0,0 +1,49 @@
+public class Counter{
+     
+  long count;
+  
+  public Counter() {
+    this.count = 0;
+  }
+
+  public synchronized void add(long value){
+    this.count += value;
+    System.printString(" " + this.count + "\n");
+  }
+  
+  public synchronized long getCounter() {
+    return this.count;
+  }
+}
+
+public class CounterThread extends Thread{
+
+  String name;
+  protected Counter counter;
+
+  public CounterThread(String name, Counter counter){
+    this.name = name;
+    this.counter = counter;
+  }
+
+  public void run() {
+    for(int i=0; i<10; i++){
+      System.printString(this.name);
+      counter.add(i);
+    }
+  }
+}
+
+public class SynchonizedTest {
+  public SynchonizedTest() {
+  }
+
+  public static void main(String[] args){
+    Counter counter = new Counter();
+    Thread  threadA = new CounterThread("A\n",counter);
+    Thread  threadB = new CounterThread("B\n",counter);
+
+    threadA.start();
+    threadB.start(); 
+  }
+}