1 // This test grew a bit more elaborate than anticipated...
2 // It verifies that the JVM handles properly the case of a thread being
3 // interrupted and notified at the same time.
5 public class waitAndInterrupt {
6 private class semaphore {
8 public semaphore(int v) {
11 public synchronized void semwait() {
15 } catch (InterruptedException e) {
19 public synchronized void sempost() {
26 public static class firstthread implements Runnable {
27 private waitAndInterrupt s;
29 public firstthread(waitAndInterrupt s_) {
33 boolean iAmFirst = Thread.currentThread() == s.t1;
42 System.out.println(Thread.currentThread().getName() + " still running, notified " + Integer.toString(count_not) + ", interrupted " + Integer.toString(count_int));
51 } catch (InterruptedException e) {
52 s.notify(); // wake t2
55 } catch (InterruptedException e) {
66 System.out.println(Thread.currentThread().getName() + " still running");
75 } catch (InterruptedException e) {
83 } catch (Exception e) {
89 public static class otherthread implements Runnable {
90 private waitAndInterrupt s;
92 public otherthread(waitAndInterrupt s_) {
96 boolean iAmFirst = Thread.currentThread() == s.t3;
104 System.out.println(Thread.currentThread().getName() + " still running");
115 System.out.println(Thread.currentThread().getName() + " still running");
119 System.out.println("shouldn't happen (1)");
127 } catch (Exception e) {
133 public static class controlthread implements Runnable {
134 private waitAndInterrupt s;
136 public controlthread(waitAndInterrupt s_) {
148 s.sem8.sempost(); // wake first
150 } catch (Exception e) {
156 public Thread t1 = null;
157 public Thread t2 = null;
158 public Thread t3 = null;
159 public Thread t4 = null;
160 public semaphore sem1 = new semaphore(0);
161 public semaphore sem2 = new semaphore(0);
162 public semaphore sem3 = new semaphore(0);
163 public semaphore sem4 = new semaphore(0);
164 public semaphore sem5 = new semaphore(0);
165 public semaphore sem6 = new semaphore(0);
166 public semaphore sem7 = new semaphore(0);
167 public semaphore sem8 = new semaphore(0);
168 public boolean notified = false;
170 public static void main(String args[]) {
171 waitAndInterrupt s = new waitAndInterrupt();
172 firstthread r1 = new firstthread(s);
173 firstthread r2 = new firstthread(s);
174 otherthread r3 = new otherthread(s);
175 controlthread r5 = new controlthread(s);
177 s.t1 = new Thread(r1, "a");
178 s.t2 = new Thread(r2, "b");
179 s.t3 = new Thread(r3, "c");
180 s.t4 = new Thread(r3, "d");
181 Thread t5 = new Thread(r5, "e");
191 * These are local overrides for various environment variables in Emacs.
192 * Please do not remove this and leave it at the end of the file, where
193 * Emacs will automagically detect them.
194 * ---------------------------------------------------------------------
197 * indent-tabs-mode: t
201 * vim:noexpandtab:sw=4:ts=4: