
Roland Schwarz schrieb: <snip> I found a small bug in my implementation. The --cv->waiters_ is unprotected. Change this to to use InterlockedDecrement(&cv->waiters_) instead.
switch(WaitForMultipleObjects( 2, cv->events_,FALSE,INFINITE)) { // on unblocking of the thread the gate is closed case WAIT_OBJECT_0+SIGNAL: InterlockedDecrement(&cv->waiters_); // one is leaving ReleaseSemaphore(cv->gate_,1,NULL);//reopen // no need to reset event, it is automatic break; case WAIT_OBJECT_0+BROADCAST: if (0 == IntelockedDecrement(&cv->waiters_)) { ResetEvent( cv->events_[BROADCAST]); // last leaving, reopen the gate ReleaseSemaphore(cv->gate_,1,NULL); } break; }
Regards, Roland