From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12341 invoked by alias); 25 Oct 2002 21:05:17 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 12280 invoked from network); 25 Oct 2002 21:05:16 -0000 Received: from unknown (HELO d12lmsgate-5.de.ibm.com) (194.196.100.238) by sources.redhat.com with SMTP; 25 Oct 2002 21:05:16 -0000 Received: from d12relay02.de.ibm.com (d12relay02.de.ibm.com [9.165.215.23]) by d12lmsgate-5.de.ibm.com (8.12.3/8.12.3) with ESMTP id g9PL59jk021258; Fri, 25 Oct 2002 23:05:09 +0200 Received: from d12ml007.de.ibm.com (d12ml007_cs0 [9.165.223.36]) by d12relay02.de.ibm.com (8.12.3/NCO/VER6.4) with ESMTP id g9PL58f8071332; Fri, 25 Oct 2002 23:05:09 +0200 Importance: Normal Sensitivity: Subject: Re: Why does cond_signal not block until a waiter is woken like cond_ broadcast does? To: "Reddie, Steven" Cc: pthreads-win32@sources.redhat.com Message-ID: From: "Alexander Terekhov" Date: Fri, 25 Oct 2002 14:05:00 -0000 MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-SW-Source: 2002/txt/msg00106.txt.bz2 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: http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/pthread_cond_signal.c?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32 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 must > be implemented in such a way that it blocks until all waiters have woken. I > assume this means it isn't specified, but if anyone knows please let me > know. Well, A) http://www.opengroup.org/onlinepubs/007904975/functions/pthread_cond_signal.html (don't miss "RATIONALE" bits) B) http://www.linux.org.uk/~ajh/ols2002_proceedings.pdf.gz (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. http://www.terekhov.de/DESIGN-futex-CV.txt http://www.terekhov.de/DESIGN-futex-CV.cpp regards, alexander. "Reddie, Steven" @sources.redhat.com on 10/25/2002 08:43:05 AM Sent by: pthreads-win32-owner@sources.redhat.com To: pthreads-win32@sources.redhat.com cc: 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 behaviour 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 progress. If pthread_cond_broadcast returned before the waiters have all woken up then further logic would be needed to both stop further broadcasts from interfering with the current one, and to stop new waiters from waking on the current broadcast thereby starving an existing waiter. I think I've figured out the required code changes, but I don't know if this is desireable behaviour. 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 = 5) * thread 0: pthread_cond_signal (semaphore incremented to 2, waiters still = 5) * thread 0: pthread_cond_signal (semaphore incremented to 3, waiters still = 5) * thread 0: pthread_cond_broadcast (waiters = 5, so sempahore is incremented 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. I assume this means it isn't specified, but if anyone knows please let me know. Regards, Steven -- Steven Reddie Development Leader - eTrust ETPKI Computer Associates Pty Ltd (Australia)