From owner-freebsd-stable@FreeBSD.ORG Thu Jun 15 13:48:48 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 5E54016A474 for ; Thu, 15 Jun 2006 13:48:48 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6AB3C43D5C for ; Thu, 15 Jun 2006 13:48:40 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.6/8.13.6/NETPLEX) with ESMTP id k5FDmdb6002425; Thu, 15 Jun 2006 09:48:39 -0400 (EDT) Date: Thu, 15 Jun 2006 09:48:39 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Mark Andrews In-Reply-To: <200606150505.k5F55CqJ054445@drugs.dv.isc.org> Message-ID: References: <200606150505.k5F55CqJ054445@drugs.dv.isc.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: stable@freebsd.org Subject: Re: gcc -pthread X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen 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 13:48:48 -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