This is due to spurious wakeups (waking up from the condition when it hasn't actually been signalled). To be safe I think you have to always check the condition once you wake up from the condition => hence the while loops

-----Original Message-----
From: boost-users-bounces@lists.boost.org on behalf of Randall Parker
Sent: Sun 3/11/2007 10:44 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [Threads] Conditions and avoiding lengthy mutexlocks (background loading for a game)

This is a reply to an April 2006 thread with two questions:

1) Why does the
    myCond.wait( myMutex );
    call happen inside a while loop rather than in an if statement? I would have
expected that since one is waiting for the queue to get something put in it that the
condition would only get set if something was placed in the queue. if one returned
from the wait and found the queue empty I'd tend to want to log that as an internal
error.