This is the mail archive of the
pthreads-win32@sourceware.cygnus.com
mailing list for the pthreas-win32 project.
Bug in pthread_cond_wait...
- To: pthreads mailing list <pthreads-win32@sourceware.cygnus.com>
- Subject: Bug in pthread_cond_wait...
- From: Lorin Hochstein <lmh@xiphos.ca>
- Date: Wed, 30 Jun 1999 14:43:16 -0400
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);