69a Subj : Re: CondVar on Windows : what to do when a consumer thread is killed To : comp.programming.threads From : adebaene Date : Fri Jul 01 2005 05:49 am Joe Seigh a =E9crit : > adebaene@club-internet.fr wrote: > > > > > What does Posix says on behaviour of a condvar whenever a waiting > > thread is killed? > > > That's there's one less thread waiting. You should stop killing off > your threads that way. Anyway, it's something you deliberately did > so you should be able to handle it. > > How did you kill the thread? I didn't killed the thread, the system did :-) The context is the following : a static singleton object starts a worker thread in it's constructor. Communication between the main thread and this worker thread is by the means of a blocking queue, which is implemented using a condvar. During the singleton destruction, a special message is posted to this queue to signal the worker thread to stop, and posting to the queue implies calling pthread_cond_broadcast. The problem is that, since the singelton is a static object, it's destructor runs during CRT termination cleanup, *after* the system has forcibly killed all worker threads --> deadlock :-( > A signal isn't guaranteed to generate > a spurious wakeup. What do you mean exactly? There is nothing left to wakeup since the consumer thread has been killed... > If you used pthread cancel then your cleanup > handlers should have taken care of the problem. I am working on Windows and do not use pthreads, but Win32 threading API (in fact, my condvar hasn't got exactly the pthread_condvar interface - although it has the same semantic). Arnaud . 0