Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / mcr-test / src / edu / tamu / aser / rvtest / omcr / Example1Lock.java
diff --git a/JMCR-Stable/mcr-test/src/edu/tamu/aser/rvtest/omcr/Example1Lock.java b/JMCR-Stable/mcr-test/src/edu/tamu/aser/rvtest/omcr/Example1Lock.java
new file mode 100644 (file)
index 0000000..aec2ed2
--- /dev/null
@@ -0,0 +1,75 @@
+package edu.tamu.aser.rvtest.omcr;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import edu.tamu.aser.reexecution.JUnit4MCRRunner;
+
+@RunWith(JUnit4MCRRunner.class)
+public class Example1Lock {
+
+       private static int x,y;
+       private static Object lock = new Object(); 
+       public static void main(String[] args) {
+               // TODO Auto-generated method stub
+               Thread t1 = new Thread(new Runnable() {
+
+                       @Override
+                       public void run() {
+                               synchronized (lock) {
+                                       int r1 = x;
+                               }
+                               
+                       }
+               });
+               
+               Thread t2 = new Thread(new Runnable() {
+
+                       @Override
+                       public void run() {
+                               y = 1;
+                       }
+               });
+               
+               Thread t3 = new Thread(new Runnable() {
+
+                       @Override
+                       public void run() {
+                               synchronized (lock) {
+                                       int r2 = y;
+                               }
+                               
+                       }
+               });
+               
+
+               t1.start();
+               t2.start();
+               t3.start();
+
+               x = 1;
+
+               try {
+                       t1.join();
+                       t2.join();
+                       t3.join();
+               } catch (InterruptedException e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       @Test
+       public void test() throws InterruptedException {
+               try {
+                       x = 0;
+                       y = 0;
+               Example1Lock.main(null);
+               } catch (Exception e) {
+                       System.out.println("here");
+                       fail();
+               }
+       }
+
+}