Interesting read.  Thanks for the info, guys.  Anyhow, I fixed this issue since it seemed like a no-brainer to fix just to be safe, and the fix made the code more efficient at least in theory anyhow.  However, based on eating my own dogfood for a long time and never running into this, I don't think it happens on x86.

On 8/31/2010 7:24 PM, Brad Roberts wrote:
On Tue, 31 Aug 2010, Sean Kelly wrote:

On Aug 31, 2010, at 12:41 PM, David Simcha wrote:
When waiting on condition variables, there's a remote chance that wait() will return when there isn't actually something to process.  Instead of:

   if (!condition)
       wait();

use:

   while (!condition)
       wait();

I saw the "if" approach in "AbstractTask* pop()"... I think that's the only one.

Thanks, will do.  How does this happen, though?
Theoretical mumbo-jumbo, mostly.  Here's the wiki entry: http://en.wikipedia.org/wiki/Spurious_wakeup  For the most part, it's just good programming practice to double-check the invariant on wakeup.
Very much not theoretical.  I've seen it happen more than a little.  A lot 
of it can be blamed on using notify all rather than notify one type 
behavior.  The other ways it can happen is signals for things like gc 
pause/resume, or pipe, or ... breaking in-progress sleeps.

It's one of the class of issues that tends not to happen in small simple 
apps, so don't learn the risks until later in some large or complex app, 
wierd things happen.

Anyway, gotta do it, it does happen.

Later,
Brad
_______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos
_______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to