Zeljko Vrba wrote:
On Mon, Aug 11, 2008 at 10:57:23PM +0300, Peter Dimov wrote:
Oops. The queue is empty. So C does sleep, awaiting a push. Why is this a problem?
Not a problem in this particular case.
Signaling outside the mutex lock is a textbook CV use which POSIX condition variables explicitly support (their implementation can be much simpler if they do not have to). You're welcome to not use it if you like, but there's nothing inherently wrong with it and it doesn't have anything to do with the original question.
A more elaborate example of what can easily go wrong with signaling outside of critical section: http://groups.google.com/group/comp.programming.threads/browse_thread/thread...
We had a similar thread a while ago. It's true that moving the signal inside the lock can solve such a CV destruction race. It might be interesting to discuss an example (if you have one) which is not easily rewritten to not have this problem.