From owner-freebsd-threads@FreeBSD.ORG Fri Sep 24 21:29:22 2010 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D19210656AA; Fri, 24 Sep 2010 21:29:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 3CC188FC0A; Fri, 24 Sep 2010 21:29:22 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id E289546B2C; Fri, 24 Sep 2010 17:29:21 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id DB95D8A04E; Fri, 24 Sep 2010 17:29:20 -0400 (EDT) From: John Baldwin To: "Jung-uk Kim" Date: Fri, 24 Sep 2010 17:24:10 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100819; KDE/4.4.5; amd64; ; ) References: <201009232220.o8NMK3fX011639@freefall.freebsd.org> <201009240926.12958.jhb@freebsd.org> <201009241137.56764.jkim@FreeBSD.org> In-Reply-To: <201009241137.56764.jkim@FreeBSD.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201009241724.10223.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 24 Sep 2010 17:29:21 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Daniel Eischen , freebsd-threads@freebsd.org Subject: Re: threads/150889: PTHREAD_MUTEX_INITIALIZER + pthread_mutex_destroy () == EINVAL X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Sep 2010 21:29:22 -0000 On Friday, September 24, 2010 11:37:53 am Jung-uk Kim wrote: > On Friday 24 September 2010 09:26 am, John Baldwin wrote: > > On Thursday, September 23, 2010 11:48:40 pm Jung-uk Kim wrote: > > > On Thursday 23 September 2010 06:44 pm, Daniel Eischen wrote: > > > > You shouldn't have to call pthread_mutex_init() on a mutex > > > > initialized with PTHREAD_MUTEX_INITIALIZER. Our implementation > > > > should auto initialize the mutex when it is first used; if it > > > > doesn't, I think that is a bug. > > > > > > Ah, I see. I verified that libthr does it correctly. However, > > > that's a hack and it is far from real static allocation although > > > it should work pretty well in reality, IMHO. More over, it will > > > have a side-effect, i.e., any destroyed mutex may be resurrected > > > if it is used again. POSIX seems to say it should return EINVAL > > > when it happens. :-( > > > > I think the fix there is that we should put a different value > > ((void *)1 for example) into "destroyed" mutex objects than 0 so > > that destroyed mutexes can be differentiated from statically > > initialized mutexes. This would also allow us to properly return > > EBUSY, etc. > > It would be nice if we had "uninitialized" as (void *)0 and "static > initializer" as (void *)1. IMHO, it looks more natural, i.e., > "uninitialized" or "destroyed" one gets zero, and "dynamically > initialized" or "statically initialized" one gets non-zero. Can we > break the ABI for 9, maybe? ;-) I actually find the (void *)1 more natural for a destroyed state FWIW. One thing I would advocate is that regardless of the values chosen, use constants for both the INITIALIZER and DESTROYED values. That would make the code more obvious. In general I think your patch in your followup is correct, but having explicitly DESTROYED constants that you check against instead of NULL would improve the code. -- John Baldwin