* tests/threadInterrupt.java: Added a test showing a bug in the pre-sable
authorStefan Ring <stefan@complang.tuwien.ac.at>
Wed, 27 Feb 2008 16:11:58 +0000 (17:11 +0100)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Wed, 27 Feb 2008 16:11:58 +0000 (17:11 +0100)
implementation.

tests/threadInterrupt.java [new file with mode: 0644]

diff --git a/tests/threadInterrupt.java b/tests/threadInterrupt.java
new file mode 100644 (file)
index 0000000..ef41083
--- /dev/null
@@ -0,0 +1,71 @@
+public class threadInterrupt {
+       public static class firstthread implements Runnable {
+               private threadInterrupt s;
+
+               public firstthread(threadInterrupt s_) {
+                       s = s_;
+               }
+               public void run() {
+                       try {
+                               synchronized (s.o1) {
+                                       System.out.println("first thread!");
+                                       Thread.sleep(500);
+                                       System.out.println("interrupting");
+                                       s.t2.interrupt();
+                                       System.out.println("leaving");
+                               }
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+       public static class secondthread implements Runnable {
+               private threadInterrupt s;
+
+               public secondthread(threadInterrupt s_) {
+                       s = s_;
+               }
+               public void run() {
+                       try {
+                               Thread.sleep(250);
+                               synchronized (s.o1) {
+                                       System.out.println("second thread!");
+                                       s.o1.wait();
+                               }
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+       public Object o1 = new Object();
+       public Thread t1 = null;
+       public Thread t2 = null;
+
+       public static void main(String args[]) {
+               System.out.println("should exit with java.lang.InterruptedException");
+               threadInterrupt s = new threadInterrupt();
+               firstthread r1 = new firstthread(s);
+               secondthread r2 = new secondthread(s);
+
+               s.t1 = new Thread(r1, "a");
+               s.t2 = new Thread(r2, "b");
+               s.t1.start();
+               s.t2.start();
+       }
+}
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: java
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */