From owner-freebsd-threads@FreeBSD.ORG Sat Aug 30 15:56:28 2008 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 7AA8010656C0; Sat, 30 Aug 2008 15:56:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 10B8F8FC0A; Sat, 30 Aug 2008 15:56:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtp (Exim 4.63 (FreeBSD)) (envelope-from ) id 1KZSoM-0003B7-82; Sat, 30 Aug 2008 18:56:26 +0300 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id m7UFuMk8078614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 30 Aug 2008 18:56:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2) with ESMTP id m7UFuM9d002399; Sat, 30 Aug 2008 18:56:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2/Submit) id m7UFuMZb002397; Sat, 30 Aug 2008 18:56:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 30 Aug 2008 18:56:22 +0300 From: Kostik Belousov To: Daniel Eischen Message-ID: <20080830155622.GF2038@deviant.kiev.zoral.com.ua> References: <48B70A98.5060501@icyb.net.ua> <48B7101E.7060203@icyb.net.ua> <48B71BA6.5040504@icyb.net.ua> <20080829141043.GX2038@deviant.kiev.zoral.com.ua> <48B8052A.6070908@icyb.net.ua> <20080829143645.GY2038@deviant.kiev.zoral.com.ua> <20080829190506.GA2038@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sD87aq2/Ee9ozic7" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1KZSoM-0003B7-82 a8d92eb016bf03b07cb6b30023912682 X-Terabit: YES Cc: davidxu@freebsd.org, Andriy Gapon , freebsd-threads@freebsd.org Subject: Re: mysterious hang in pthread_create 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: Sat, 30 Aug 2008 15:56:28 -0000 --sD87aq2/Ee9ozic7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Aug 30, 2008 at 11:32:35AM -0400, Daniel Eischen wrote: > On Fri, 29 Aug 2008, Kostik Belousov wrote: >=20 > >On Fri, Aug 29, 2008 at 12:25:09PM -0400, Daniel Eischen wrote: > >>On Fri, 29 Aug 2008, Kostik Belousov wrote: > >> > >>>On Fri, Aug 29, 2008 at 05:18:18PM +0300, Andriy Gapon wrote: > >>>> > >>>>Kostik, thanks! > >>>> > >>>>on 29/08/2008 17:10 Kostik Belousov said the following: > >>>>>I am wondering why did you not fixed it youself with all this > >>>>>information. > >>>> > >>>>I am wondering that myself now :-) > >>>>I got bogged in rtld details and simply didn't think about the soluti= on > >>>>of doing setthreaded earlier. > >>>> > >>>>I will try your patch a couple of hours later. > >>>>BTW, a forward question - should this patch help in the case of an > >>>>exception thrown (and caught) before main(), i.e. in constructors of > >>>>static/global objects? > >>>If the objects are from the executable, then yes. I do not know about > >>>present situation, but some time ago g++ and several other compilers > >>>called ctr for global objects from the main() function. Regardeless > >>>of this, init for main executable shall be called after init for > >>>dependencies is finished. See initlist_add_objects(). > >>> > >>>On the other hand, ctr calls from linked dso may get fixed in regard > >>>of exception throwing, or may not, depending on the relative order of > >>>the dso loading against libthr. > >>> > >>>> > >>>>>Anyway, patch below seems to work for me. David may have an opinion = on > >>>>>the change. > >>>>> > >>>>>diff --git a/lib/libthr/thread/thr_init.c=20 > >>>>>b/lib/libthr/thread/thr_init.c > >>>>>index f96bba9..785d610 100644 > >>>>>--- a/lib/libthr/thread/thr_init.c > >>>>>+++ b/lib/libthr/thread/thr_init.c > >>>>>@@ -355,6 +355,9 @@ _libpthread_init(struct pthread *curthread) > >>>>> if (_thread_event_mask & TD_CREATE) > >>>>> _thr_report_creation(curthread, curthread); > >>>>> } > >>>>>+ > >>>>>+ if (_thr_isthreaded() =3D=3D 0) > >>>>>+ _thr_setthreaded(1); > >>>>>} > >>>>> > >>>>>/* > >> > >>I think the intent of __isthreaded (and _thr_setthreaded()) was > >>to be set if there were more than 1 thread, not to indicate that > >>the thread library has been initialized. > > > >As demonstrated by Andriy' example, we need _thr_rtld_init() be called > >before any rtld locks are given chance to be acquired. _thr_rtld_init() > >shall be protected from repeated invocation, and _thr_setthreaded() > >implements exactly this. > > > >If calling _thr_setthreaded(1) has not quite right intent, could you, > >please, suggest satisfying solution ? >=20 > I'm not sure I _quite_ understand the problem, but why > wouldn't you have the same potential problem with some > other library (without libthread)? I'll have to go back > and read the beginning of the thread - I just kinda came > in at the end. Sure, for appropriate value of any. If you mean whether the same problem would arise for any threading library that supplies locking implementation for rtld, then certainly yes. I looked over and patched only libthr since this is the only survived library for now. Anyway, I do not insist on the proposed solution, and definitely prefer the change that is well aligned with libthr architecture. --sD87aq2/Ee9ozic7 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAki5baUACgkQC3+MBN1Mb4ga9gCeNbQi4PbFTFPwniFlJVkzHB5c CasAn3wGRFZ6znpjR5HqAYwu6ffuWrTI =63Dm -----END PGP SIGNATURE----- --sD87aq2/Ee9ozic7--