This is the mail archive of the
mailing list for the pthreas-win32 project.
Re: Why does cond_signal not block until a waiter is woken like cond_ broadcastdoes?
- From: "Alexander Terekhov" <TEREKHOV at de dot ibm dot com>
- To: "Reddie, Steven" <Steven dot Reddie at ca dot com>
- Cc: pthreads-win32 at sources dot redhat dot com
- Date: Fri, 25 Oct 2002 23:05:06 +0200
- Subject: Re: Why does cond_signal not block until a waiter is woken like cond_ broadcastdoes?
Steven Reddie wrote:
> pthread_cond_broadcast doesn't return until all waiters have woken.
Uhmm. Since when? Well, looking at the CVS stuff available here:
I just fail to understand what do you mean saying "pthread_cond_broadcast
doesn't return until all waiters have woken".
Perhaps you can clarify it a little bit.
> Also, I can't determine from the POSIX docs if pthread_cond_broadcast
> be implemented in such a way that it blocks until all waiters have woken.
> assume this means it isn't specified, but if anyone knows please let me
(don't miss "RATIONALE" bits)
(Acrobat: "479 of 631", read on "futexes")
C) Consider the following stuff that might help you [as usual,
modulo bugs and any thing(s) that I've myself missed and/
or misunderstood] understand how it is all meant to work.
"Reddie, Steven" <Steven.Reddie@ca.com>@sources.redhat.com on 10/25/2002
Sent by: firstname.lastname@example.org
Subject: Why does cond_signal not block until a waiter is woken like
cond_ broadcast does?
Hi, I don't think I've found a bug but am just wondering about the
of the condition variables.
pthread_cond_broadcast doesn't return until all waiters have woken. This
would seem to stop any new waiters from grabbing the semaphore meant for an
existing waiter, since the mutex is held for the duration of
pthread_cond_broadcast. This would also seem to stop any subsequent
broadcast or signal calls from other threads while the first is in
If pthread_cond_broadcast returned before the waiters have all woken up
further logic would be needed to both stop further broadcasts from
interfering with the current one, and to stop new waiters from waking on
current broadcast thereby starving an existing waiter. I think I've
out the required code changes, but I don't know if this is desireable
However, pthread_cond_signal does not do this, it simply increments the
semaphore count and immediately returns. This makes me think that there is
a potential problem if a few signal calls are followed by a broadcast call
without any of the waiting threads waking in between. To illustrate:
* threads 1-5: all waiting on the same condition variable (waiters now = 5)
* thread 0: pthread_cond_signal (semaphore incremented to 1, waiters still
* thread 0: pthread_cond_signal (semaphore incremented to 2, waiters still
* thread 0: pthread_cond_signal (semaphore incremented to 3, waiters still
* thread 0: pthread_cond_broadcast (waiters = 5, so sempahore is
by 5, to 8)
If this is what happens then this would result in a deadlock, because no
more waiters can be added while cond_broadcast holds the lock, but until a
further 3 waiters come along the cond_broadcast call cannot complete.
Surely I'm missing something, but please let me know either way.
Also, I can't determine from the POSIX docs if pthread_cond_broadcast must
be implemented in such a way that it blocks until all waiters have woken.
assume this means it isn't specified, but if anyone knows please let me
Steven Reddie <Steven.Reddie@ca.com>
Development Leader - eTrust ETPKI
Computer Associates Pty Ltd (Australia)