Re: JavaMemoryModel: Waits, Interrupts and Notify-s

From: Thomas Maslen (maslen@pobox.com)
Date: Fri May 23 2003 - 21:46:34 EDT


[...]
> 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.

I don't think that Pthreads allowed spurious wakeups just to be perverse;
I believe (but can't say for sure) that they did it because mandating no
spurious wakeups would have ugly consequences for the implementation on at
least some platforms[*]. If that's too vague, should we ask Dave Butenhof?

Besides, given that the idiom for using wait() should always, always,
always (right?) be

        synchronized (m)
        {
            ...
            while (! condition... )
            {
                m.wait();
                ...
            }
        }

i.e. wrapping the wait() in a while-loop, it doesn't worry me that the
responsibility for handling spurious wakeups rests with the programmer (me).

Thomas Maslen
maslen@pobox.com

[*] The Pthreads API has the same sorts of cross-platform abstraction/
    portability goals and resulting issues that Java does. It also
    represents a largish subset of the platforms on which people run
    J2SE and J2EE. Hell, maybe J2ME too, given the rise of Linux there.
-------------------------------
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