From owner-freebsd-current@FreeBSD.ORG Wed Apr 20 02:13:57 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8587E1065674; Wed, 20 Apr 2011 02:13:57 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 735F58FC08; Wed, 20 Apr 2011 02:13:57 +0000 (UTC) Received: from xyf.my.dom (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p3K2DnHb060787; Wed, 20 Apr 2011 02:13:56 GMT (envelope-from davidxu@freebsd.org) Message-ID: <4DAE4164.9080006@freebsd.org> Date: Wed, 20 Apr 2011 10:13:56 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.13) Gecko/20110127 Thunderbird/3.1.7 MIME-Version: 1.0 To: Ryan Stone References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: FreeBSD Current , Ed Maste Subject: Re: [PATCH] Call _thr_check_init() from _pthread_once X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2011 02:13:57 -0000 On 2011/04/20 00:53, Ryan Stone wrote: > In r179417 the implementation of pthread_once in libthr was changed > from using a global pthread_mutex_t for synchronization to rolling its > own synchronization mechanism. Unfortunately, this introduced a bug. > Calling _pthread_mutex_lock implicitly ensured that _thr_check_init() > had been called. In the current version, there is no such guarantee. > This means that if your first call into libthr is pthread_once, your > executable will segfault when it tries to access curthread. This > patch resolves the issue for me: > > Index: lib/libthr/thread/thr_once.c > =================================================================== > --- lib/libthr/thread/thr_once.c (revision 220603) > +++ lib/libthr/thread/thr_once.c (working copy) > @@ -64,6 +64,8 @@ > struct pthread *curthread; > int state; > > + _thr_check_init(); > + > for (;;) { > state = once_control->state; > if (state == ONCE_DONE) > > If there are no objections I'll commit this soon. Have you tested that current code causes segfault ? anyway, I can not reproduce it on my machne. Regards, David Xu