* tests/threads/threadInterrupt.java: Added brief comment explaining the
[cacao.git] / tests / threads / threadInterrupt.java
1 // This test has been added because of a bug in CACAO that allowed threads
2 // blocked inside monitorenter to be interrupted. In the presence of the bug,
3 // the program would not exit.
4 //
5 // The bug has been fixed as part of the sable lock implementation.
6 // hg revision 2988182011bb ff (Wed Feb 06 18:46:34 2008 +0100)
7
8 public class threadInterrupt {
9         public static class firstthread implements Runnable {
10                 private threadInterrupt s;
11
12                 public firstthread(threadInterrupt s_) {
13                         s = s_;
14                 }
15                 public void run() {
16                         try {
17                                 synchronized (s.o1) {
18                                         System.out.println("first thread!");
19                                         Thread.sleep(500);
20                                         System.out.println("interrupting");
21                                         s.t2.interrupt();
22                                         System.out.println("leaving");
23                                 }
24                         } catch (Exception e) {
25                                 e.printStackTrace();
26                         }
27                 }
28         }
29
30         public static class secondthread implements Runnable {
31                 private threadInterrupt s;
32
33                 public secondthread(threadInterrupt s_) {
34                         s = s_;
35                 }
36                 public void run() {
37                         try {
38                                 Thread.sleep(250);
39                                 synchronized (s.o1) {
40                                         System.out.println("second thread!");
41                                         s.o1.wait();
42                                 }
43                         } catch (Exception e) {
44                                 e.printStackTrace();
45                         }
46                 }
47         }
48
49         public Object o1 = new Object();
50         public Thread t1 = null;
51         public Thread t2 = null;
52
53         public static void main(String args[]) {
54                 System.out.println("should exit with java.lang.InterruptedException");
55                 threadInterrupt s = new threadInterrupt();
56                 firstthread r1 = new firstthread(s);
57                 secondthread r2 = new secondthread(s);
58
59                 s.t1 = new Thread(r1, "a");
60                 s.t2 = new Thread(r2, "b");
61                 s.t1.start();
62                 s.t2.start();
63         }
64 }
65
66 /*
67  * These are local overrides for various environment variables in Emacs.
68  * Please do not remove this and leave it at the end of the file, where
69  * Emacs will automagically detect them.
70  * ---------------------------------------------------------------------
71  * Local variables:
72  * mode: java
73  * indent-tabs-mode: t
74  * c-basic-offset: 4
75  * tab-width: 4
76  * End:
77  * vim:noexpandtab:sw=4:ts=4:
78  */