From owner-freebsd-threads@FreeBSD.ORG Wed Dec 21 20:10:13 2011 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C09E61065670 for ; Wed, 21 Dec 2011 20:10:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id AFA9C8FC16 for ; Wed, 21 Dec 2011 20:10:13 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id pBLKAD6p064848 for ; Wed, 21 Dec 2011 20:10:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id pBLKAD46064847; Wed, 21 Dec 2011 20:10:13 GMT (envelope-from gnats) Date: Wed, 21 Dec 2011 20:10:13 GMT Message-Id: <201112212010.pBLKAD46064847@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Daniel Eischen Cc: Subject: Re: threads/163512: libc defaults to single threaded X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2011 20:10:13 -0000 The following reply was made to PR threads/163512; it has been noted by GNATS. From: Daniel Eischen To: Steven Wills Cc: freebsd-gnats-submit@freebsd.org, freebsd-threads@freebsd.org Subject: Re: threads/163512: libc defaults to single threaded Date: Wed, 21 Dec 2011 14:28:58 -0500 (EST) >> Description: > 1) libc defaults to being single-threaded > 2) thus apps not linked against libthr don't initialize the structures that threading depends on > 3) this causes bugs when said app loads a library that loads libthr > 4) said library will take the threaded code path and reference uninitialized data structures > > An example of this can be seen by removing ports/devel/p5-Glib2/files/patch-threadstest then after building, run "make test" from work/Glib-1.241. Perl will hang in state umtxn. > > I believe this may also be the source of an intermittent hang in automoc4 (also stuck in state umtxn) seen while building x11/kde4. This was discussed here: > > http://mail.kde.org/pipermail/kde-freebsd/2011-November/012211.html > https://bugs.kde.org/show_bug.cgi?id=276461 This has always been the case. If an application is going to be linked to a library that requires threads, then that application has to link to libpthread. Applications should be built knowing whether libpthread will be required or not. Either that, or the library should be built to detect whether threading is present and only use thrading features when threading is present (see how libgcc does this as example). The former or latter depends on the what the library is trying to provide. If it needs to spawn threads to accomplish its job, then the former (application needs to link with libpthread). If the library just needs synchronization primitives to protect against a threaded application, then you can use the latter. If the application is kinda stupid and really doesn't know if threads are required, then there probably is no harm in always linking to libpthread. -- DE