I have a situation where I'd like to set up a queue that's filled by one 
thread and read by another thread.  However, I don't want the consumer thread 
to busy-wait when the queue is empty, to avoid chewing the CPU.

My original thought was to use a ConditionVariable.  Ie, when the consumer 
thread finds that the length of the queue is currently zero it then does a 
wait on a ConditionVariable, using the mutex that's guarding the queue.

But, how does the producer thread know for certain that it needs to signal the 
condition variable?

You could do the signal only when the size of the queue is zero just before 
you append a new entry, but the fact that it's empty doesn't mean someone's 
actually waiting for it to become non-empty.

The consumer thread could currently be processing the last entry it retrieved 
and by the time it gets back, the new entry may already be there, hence it 
wouldn't do the wait.

I note that the documentation in PR says that ConditionVariable.signal() wakes 
up the first thread in line waiting for the lock.  Does that mean that if 
noone is waiting, the signal just gets thrown away?  In that case, things may 
be OK.

Anyway, I guess you get the picture.  Is there a clean way to handle this 
situation?  Maybe there's a library or class I'm not aware of that provides 
this kind of blocking queue.

Thanks in advance,

Harry O.