Subj : CondVar on Windows : what to do when a consumer thread is killed To : comp.programming.threads From : adebaene Date : Fri Jul 01 2005 03:09 am Hello all, I am using an implementation of condvars on Win32 based on the one that is described here : http://www.cs.wustl.edu/~schmidt/win32-cv-1.html. (I am using the 3.4 solution : the one using SignalAndWait). It works great (at least for my needs) except in one situation : Say I have only 1 thread holding the condvar (blocked calling pthread_cond_wait). If this thread is killed, the waiters_count "leaks" (waiters_count==1 while there is no waiters left). If, after that, another thread try to call pthread_cond_broadcast, it will block forecever waiting on the " WaitForSingleObject (cv->waiters_done_, INFINITE);" line inside this function, because no thread will ever set the waiters_done event. Does anyone have a solution to detect this situation and avoid the deadlock? I thought about having a timeout on WaitForSingleObject(waiters_done), but I don't know what value to give to this timeout, and even like that, what to do in case of timeout, since the semaphore has already been released and I've got no idea of the state of awaiting threads. What does Posix says on behaviour of a condvar whenever a waiting thread is killed? Thanks, Arnaud .