This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [win32] notifyAll also notifying following wait calls


> -----Original Message-----
> From:  Tom Tromey
> Marco> [Object.wait()] is allowed to be notified from the preceding 
> notifyAll() call?
> 
> I didn't read that closely, since it can wake up for no reason at all.
> User code has to expect this, which is why the proper way to use
> wait() is to call it in a loop and then check some external 
> condition before exiting the loop.
> 
In the vast majority of cases, this is true anyway, since some other
threads could have come in between notify/notifyAll and the wait,
invalidating the condition that was signalled by the notify.  One
argument for allowing spurious wakeups is that it less likely that
people will erroneously omit the loop.  And conversely, given that the
loop has to be there anyway, there's no good reason to have the runtime
work really hard to avoid spurious wakeups.  (Of course, a lot of
spurious wakeups turn into a performance problem.)

Hans


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]