From owner-freebsd-stable@FreeBSD.ORG Thu Jun 15 14:34:45 2006 Return-Path: X-Original-To: stable@freebsd.org Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D7CA216A474; Thu, 15 Jun 2006 14:34:45 +0000 (UTC) (envelope-from Mark_Andrews@isc.org) Received: from farside.isc.org (farside.isc.org [204.152.187.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8EADB43D45; Thu, 15 Jun 2006 14:34:45 +0000 (GMT) (envelope-from Mark_Andrews@isc.org) Received: from drugs.dv.isc.org (localhost.isc.org [IPv6:::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by farside.isc.org (Postfix) with ESMTP id D091CE6009; Thu, 15 Jun 2006 14:34:44 +0000 (UTC) (envelope-from marka@isc.org) Received: from drugs.dv.isc.org (localhost [127.0.0.1]) by drugs.dv.isc.org (8.13.6/8.13.6) with ESMTP id k5FEYff4035434; Fri, 16 Jun 2006 00:34:42 +1000 (EST) (envelope-from marka@drugs.dv.isc.org) Message-Id: <200606151434.k5FEYff4035434@drugs.dv.isc.org> To: Daniel Eischen From: Mark Andrews In-reply-to: Your message of "Thu, 15 Jun 2006 09:48:39 -0400." Date: Fri, 16 Jun 2006 00:34:41 +1000 Sender: Mark_Andrews@isc.org Cc: stable@freebsd.org Subject: Re: gcc -pthread X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jun 2006 14:34:45 -0000 > On Thu, 15 Jun 2006, Mark Andrews wrote: > > > > > Is there any good reason why "gcc -pthread" links in > > -lpthead except when -shared is specified? > > Because one may want to build applications to use different > threading libraries. Application A may work better with libthr, > while application B prefers libpthread. Both applications may > also rely on libfoo which needs a threading library in order > to be MT-safe. If libfoo records a dependency on libpthread, > and application A uses libthr, then that won't work (crashy > crashy). > > I think we took the approach a long time ago that there > were basically 2 reasons for a library to require threading: > > 1) To be MT-safe when used in the presence of a threaded > application; and > > 2) To create threads behind the scenes in support of an > application (i.e., a hypothetical libaio). > > In the case of 1, the library can use #pragma weak on > pthread_create and detect whether or not a threads > library is present and only use locking when pthread_create > != NULL (libc provides stubs for all the pthread functions > necessary for locking). In the case of 2, applications > should know what libraries need threads and be required > to supply -lpthread (or -lthr, or -pthread) when they are > built. > > This may or may not change in the future because all > the UNIX world is Linux :( (And for possible problems > when using symbol versioning.) > > > Also the gcc man page does not match reality. > > > > -pthread > > Link a user-threaded process against libc_r instead of libc. > > > > man pthread mentions these libraries but provided no discussion > > on if or when you should include them on the command line. Nor > > does it mention "-pthread". > > > > LIBRARY > > POSIX Threads Library (libpthread, -lpthread) > > 1:1 Threading Library (libthr, -lthr) > > Reentrant C Library (libc_r, -lc_r) > > > > The hacker handbook seems to indicate that you shouldn't need > > to use -lpthread or -lc_r. > > > > http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/dads- > pthread.html > > That's the porters handbook and they prefer to use PTHREAD_LIBS so > one can override the default threading library when building the > port. PTHREAD_LIBS defaults to -pthread because -pthread does > the right thing on different archs where the default threading > library varies (x86, amd64, ia64 use libpthread, sparc64 uses > libthr, etc). > > -- > DE Thanks. From this I take it the best way to build a threaded library under FreeBSD is to not specify a threads library when specifying -shared to gcc. Hopefully someone will take this and add a page to the handbook which explains all this. Mark -- Mark Andrews, ISC 1 Seymour St., Dundas Valley, NSW 2117, Australia PHONE: +61 2 9871 4742 INTERNET: Mark_Andrews@isc.org