From owner-freebsd-hackers@FreeBSD.ORG Mon Feb 28 15:08:38 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 89C261065672 for ; Mon, 28 Feb 2011 15:08:38 +0000 (UTC) (envelope-from yuri@rawbw.com) Received: from shell0.rawbw.com (shell0.rawbw.com [198.144.192.45]) by mx1.freebsd.org (Postfix) with ESMTP id 755EB8FC18 for ; Mon, 28 Feb 2011 15:08:38 +0000 (UTC) Received: from MacBook.local (stunnel@localhost [127.0.0.1]) (authenticated bits=0) by shell0.rawbw.com (8.14.4/8.14.4) with ESMTP id p1SF5eqL009862; Mon, 28 Feb 2011 07:05:41 -0800 (PST) (envelope-from yuri@rawbw.com) Message-ID: <4D6BBA70.8010503@rawbw.com> Date: Mon, 28 Feb 2011 07:08:32 -0800 From: Yuri User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <4D6ABA14.80208@rawbw.com> <4D6AC17A.7020505@rawbw.com> <201102280309.56631.pieter@degoeje.nl> In-Reply-To: <201102280309.56631.pieter@degoeje.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Pieter de Goeje Subject: Re: Is pthread_cond_signal(3) man page correct? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Feb 2011 15:08:38 -0000 On 28.02.11 2:41, Pieter de Goeje wrote: > pthread_cond_signal() can indeed wake up more than one thread. That's why you > should always wrap pthread_cond_wait() in a loop. For example a blocking > queue could be implemented like this (pseudo code): Thank you. Now its clear that POSIX allows multiple wake ups. But my question is: why would the standard define it this way? Why would it allow essentially arbitrary number of waiting threads to be woken up by one event? I can't think of any practical app that would need "some threads to be woken up". It would be natural to expect it to wake exactly one thread. So the users won't need to have any special cycles like you suggested in your previous post. What is the underlying reason for POSIX to define it this way and for OSes to implement it this way? Yuri