JavaMemoryModel: Waits, Interrupts and Notify-s

Date: Fri May 23 2003 - 17:03:15 EDT

Hi folks,

Some issues with wait, notify and interrupt have come up, and they are
interesting enough that you folks may want to look at them.

Basically, they boil down to the situations:

1) Thread 1 is waiting on a monitor, and Thread 2 performs a notify on
that monitor followed by an interrupt on Thread 1.

2) Thread 1 is waiting on a monitor, and Thread 2 performs an interrupt on
Thread 1 followed by a notify on the monitor.

JVMs don't standardize behavior much around this; some of them seem to
report InterruptedException in both cases, and some of them wake up in
both cases.

There are a few questions here:

a) Let's say there is another thread (Thread 3) waiting on the same
monitor. If Thread 1 gets the notify and then is interrupted (throwing
the IE), can the notify disappear, or should we enforce that Thread 3 gets

Just to inform this a little more, if we did not enforce this notion, the
programmer shuold issue an extra notify (if those are the semantics the
programmer wants for the programmer's code). Otherwise, the VM should
issue it.

b) Should the (notify; interrupt) vs. (interrupt; notify) ordering matter
here? For example, it could be enforced that
        (interrupt; notify) means we always guarantee that Thread 3 was
                woken, whereas
        (notify; interrupt) means either Thread 3 may be woken, or
                potentially Thread 1 may return from wait normally but in
                an interrupted state.
Or, should both ways around could have the same results?

c) Finally, JSR-166 now mandates that wakeups can happen at more-or-less
random. This isn't really a question, so much as it is the observation
that there are now additional notify-s that can happen surprisingly.

What are your thoughts on how these issues should play out in the spec?

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:45 EDT