A queue thread processes a STL queue, basically doing ...

while ( TRUE )
{
if ( pqueue->empty() )
{
// auto-reset event
WaitForSingleObject(hQueueResumeEvent, INFINITE);
}
p = pqueue->first();
// process data
EnterCriticalSection(&ccQueueWrite);
pqueue->pop();
LeaveCriticalSection(&ccQueueWrite);
}

In another thread, a CompletionRoutine for ReadDirectoryChangesW() does

EnterCriticalSection(&ccQueueWrite)
queue->push()
LeaveCriticalSection(&ccQueueWrite)
SetEvent(hResumeQueueThread)

I find that after that push() and SetEvent(), the queue thread may crash upon accessing queue->first().

In further testing, using "while" (my fix for now) instead of "if" ...

while ( pqueue->empty() )
{
WaitForSingleObject(hQueueResumeEvent, INFINITE);
}
p = pqueue->first();

... I find that the WaitFor... sometimes happens twice; i.e., pqueue->empty() is TRUE even after the push/SetEvent by another thread.

Can someone please explain what's happening and maybe suggest other fixes? Don't all threads share the same, coherent view of the queue after pqueue->push() returns?

Thanks!

- Vince