Bug in pthread_cond_wait...

Lorin Hochstein lmh@xiphos.ca
Wed Jun 30 11:44:00 GMT 1999


As mentioned in my previous post, I believe there is a bug in the
pthread_cond_wait code. If the thread is cancelled while blocked in a
pthread_cond_wait, it does not properly restore the condition variable's
state, which can cause a subsequent call to pthread_cond_broadcast to
hang (broadcast will wait forever for the terminated thread to respond).
This is a big problem if you have one producer and multiple consumers,
and one of the consumers gets cancelled.

I don't know what the correct protocol is for submitting bugfixes.
However, for the impatient ones that are encountering the same problem
that I am attaching a patch with this e-mail.

Lorin Hochstein
478a479,489
> 
> static int
> _restore_cond(void *cond)
> {
>   pthread_cond_t cv;
>   cv = *(pthread_cond_t*)cond;
>   cv->waiters--;
>   return 0;
> }
> 
> 
536a548,550
>        *
>        *      We must also ensure that the condition variable is 
>        *      restored to the correct state.
538a553
>       pthread_cleanup_push (_restore_cond, cond);
544a560
>       pthread_cleanup_pop (0);


More information about the Pthreads-win32 mailing list