[phobos] std.parallelism: Request for review/comment
Brad Roberts
braddr at puremagic.com
Tue Aug 31 16:24:41 PDT 2010
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
-------------- next part --------------
_______________________________________________
phobos mailing list
phobos at puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list