|
-
July 1st, 2011, 09:39 PM
#1
Win32/queue(STL)/threads?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|