From: jzhou Date: Thu, 14 Oct 2010 17:59:34 +0000 (+0000) Subject: Add Test for multicore gc version w/o tasks X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1f5c6d110c6177a64125db8f2feb20d47aec3037;p=IRC.git Add Test for multicore gc version w/o tasks --- diff --git a/Robust/src/Tests/MGC/SynchonizedTest.java b/Robust/src/Tests/MGC/SynchonizedTest.java new file mode 100644 index 00000000..bb63fb18 --- /dev/null +++ b/Robust/src/Tests/MGC/SynchonizedTest.java @@ -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(); + } +}