1 // This should run forever. If it stops, that's a good indication for a bug in
4 // This test grew a bit more elaborate than anticipated...
5 // It verifies that the JVM handles properly the case of a thread being
6 // interrupted and notified at the same time.
8 public class waitAndInterrupt {
9 private class semaphore {
11 public semaphore(int v) {
14 public synchronized void semwait() {
18 } catch (InterruptedException e) {
22 public synchronized void sempost() {
29 public static class firstthread implements Runnable {
30 private waitAndInterrupt s;
32 public firstthread(waitAndInterrupt s_) {
36 boolean iAmFirst = Thread.currentThread() == s.t1;
45 System.out.println(Thread.currentThread().getName() + " still running, notified " + Integer.toString(count_not) + ", interrupted " + Integer.toString(count_int));
54 } catch (InterruptedException e) {
55 s.notify(); // wake t2
58 } catch (InterruptedException e) {
69 System.out.println(Thread.currentThread().getName() + " still running");
78 } catch (InterruptedException e) {
86 } catch (Exception e) {
92 public static class otherthread implements Runnable {
93 private waitAndInterrupt s;
95 public otherthread(waitAndInterrupt s_) {
99 boolean iAmFirst = Thread.currentThread() == s.t3;
107 System.out.println(Thread.currentThread().getName() + " still running");
118 System.out.println(Thread.currentThread().getName() + " still running");
122 System.out.println("shouldn't happen (1)");
130 } catch (Exception e) {
136 public static class controlthread implements Runnable {
137 private waitAndInterrupt s;
139 public controlthread(waitAndInterrupt s_) {
151 s.sem8.sempost(); // wake first
153 } catch (Exception e) {
159 public Thread t1 = null;
160 public Thread t2 = null;
161 public Thread t3 = null;
162 public Thread t4 = null;
163 public semaphore sem1 = new semaphore(0);
164 public semaphore sem2 = new semaphore(0);
165 public semaphore sem3 = new semaphore(0);
166 public semaphore sem4 = new semaphore(0);
167 public semaphore sem5 = new semaphore(0);
168 public semaphore sem6 = new semaphore(0);
169 public semaphore sem7 = new semaphore(0);
170 public semaphore sem8 = new semaphore(0);
171 public boolean notified = false;
173 public static void main(String args[]) {
174 waitAndInterrupt s = new waitAndInterrupt();
175 firstthread r1 = new firstthread(s);
176 firstthread r2 = new firstthread(s);
177 otherthread r3 = new otherthread(s);
178 controlthread r5 = new controlthread(s);
180 s.t1 = new Thread(r1, "a");
181 s.t2 = new Thread(r2, "b");
182 s.t3 = new Thread(r3, "c");
183 s.t4 = new Thread(r3, "d");
184 Thread t5 = new Thread(r5, "e");
194 * These are local overrides for various environment variables in Emacs.
195 * Please do not remove this and leave it at the end of the file, where
196 * Emacs will automagically detect them.
197 * ---------------------------------------------------------------------
200 * indent-tabs-mode: t
204 * vim:noexpandtab:sw=4:ts=4: