RE: JavaMemoryModel: Thread model algorithm.

From: David Holmes (
Date: Mon Nov 17 2003 - 18:10:15 EST

Sylvia Else wrote:
> So the only tangible benefit of attaching a higher priority
> to interrupt() is that the programmer who is concerned to get
> maximally fast response to interrupt() (and doesn't care about
> lost notifications) does not have to add
> if(Thread.interrupted()) throw InterruptedException;
> immediately after the call to wait.
> Having lost notifications and/or spurious wakeups inherent
> in the model seems a high price to pay for this.

I don't think we should conflate spurious wakeups with lost

The possibility of spurious wakeups force the programmer to do the
right thing by always checking conditions in a loop. This is a Good
Thing (TM). Not allowing spurious wakeups would do more harm than good
in my opinion.

Attaching higher priority to interrupts does not have to result in
lost notifications - that is the whole crux of this argument: whether
an implementation that effectively does:

          if(Thread.interrupted()) throw new InterruptedException();

at the end of wait() has to deal with the fact that a notification may
have been consumed by the thread. The consensus was that it must. One
way to do this is to perform a notifyAll that could appear as a
spurious wakeup to some threads.

Obviously if spurious wakeups were not allowed then solving this
problem would be much harder - perhaps impossible.

Note that an implementation is not required to give higher priority to

David Holmes

JavaMemoryModel mailing list -

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