At 05:03 PM 23/05/2003 -0400, jmanson@cs.umd.edu wrote:
>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.
Why shouldn't we regard some JVMs as broken, depending on what they do? 
Consider
synchronized(m)
{
     // Suppose threads p and t are current in the wait set for m. The 
current thread can establish
     // this fact by appropriate use of volatile variables.
     t.interrupt();
     // Thread t is definitely no longer in the wait set for m, and will throw
     // an InterruptedException when it runs.
     m.notify();
     // Thread p is definitely no longer in the wait set for m, and will 
run in due course.
}
or
synchronized(m)
{
     // Suppose threads p and t are current in the wait set for m. The 
current thread can establish
     // this fact be appropriate use of volatile variables.
     m.notify();
     // Either p is not in the wait set, or t is not in the wait set.
     t.interrupt();
     // If t was still in the wait set, then both p and t are ready to run, 
and t will throw an InterruptedException.
     // If t was not still in the wait set, then t will not throw 
InterruptedException when it runs but will have its interrupted flag set, 
and p is sill in the wait set.
     // Therefore there will be exactly one thread that runs without 
throwing an InterruptedException,
     // and if an InterruptedException is thrown, then both threads will run.
}
Why do we have to allow spurious wakeups at all? If the underlying OS 
threading causes spurious wakeups, then the JVM implementation should hide 
them.
Sylvia.
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:45 EDT