
Mark, The problem is that your "get" waits on the condition before it checks if the condition has already been met. So if you call "get" after the producer has already "post"ed, you'll sit on the condition forever. The canonical form of waiting on a condition looks like this:
MSG mqueue::get(); { MSG msgResult; { boost::mutex::scoped_lock lockQueue( _mutexQueue ); while ( _queueOut.empty() ) _conditionMessageReady.wait( lockQueue );
msgResult = _queueOut.front(); _queueOut.pop(); } return msgResult; }
Now if you call get and there's something in the queue, there's no need to wait on the condition.
P.S. The lockQueue is locked when the condition is done waiting, right?
Yes, the lock is automatically released when entering wait, and acquired before exiting it. Hope this helps! Christopher