RE: JavaMemoryModel: Thread model algorithm.

From: Jerry Schwarz (jerry.schwarz@oracle.com)
Date: Tue Nov 18 2003 - 15:32:10 EST


At 03:10 PM 11/17/2003, David Holmes wrote:
>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
>notifications.
>
>The possibility of spurious wakeups force the programmer to do the
>right thing by always checking conditions in a loop.

Unfortunately it doesn't force programmers to do anything. It merely means
that if the programmer fails to take spurious wakeups into account there
will be a bug in the code that may lurk there for a very long time. Likely
there will be sporadic reports of failures that are hard to reproduce. And
a programmer who isn't aware of the possibility of spurious wakeups will
stare at the code and not see anything wrong.

> 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
>interrupts.
>
>David Holmes
>
>-------------------------------
>JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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