From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 21 09:52:04 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 55F0216A4CE; Wed, 21 Apr 2004 09:52:04 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id DCCC843D39; Wed, 21 Apr 2004 09:52:03 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.10/8.12.1) with ESMTP id i3LGq3tf008155; Wed, 21 Apr 2004 12:52:03 -0400 (EDT) Date: Wed, 21 Apr 2004 12:52:03 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Joe Marcus Clarke In-Reply-To: <1082564941.845.6.camel@gyros> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@FreeBSD.org Subject: Re: Help: threading problem in non-threaded applications X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Apr 2004 16:52:04 -0000 On Wed, 21 Apr 2004, Joe Marcus Clarke wrote: > On Wed, 2004-04-21 at 09:18, Daniel Eischen wrote: > > On Wed, 21 Apr 2004, Joe Marcus Clarke wrote: > > > > > On Tue, 2004-04-20 at 17:08, Daniel Eischen wrote: > > > > On Tue, 20 Apr 2004, Joe Marcus Clarke wrote: > > > > > > > > > I have a problem I'm hoping someone can help me with. GTK+ 2.4 > > > > > introduced a new file selection GUI which works just fine in threaded > > > > > and non-threaded applications. However, GNOME 2.6 augmented this dialog > > > > > with a dynamically loadable threaded shared object. The GNOME version > > > > > is automatically used by all GTK+ apps when run under a GNOME desktop if > > > > > libgnomeui is installed. > > > > > > > > Shared libraries shouldn't link with threading libraries > > > > unless they actually create threads behind the scenes. > > > > Actually, even so, they could force the (unthreaded) > > > > applications that link with them to explicitly supply > > > > the thread library in the link option. > > > > > > And that's the case here. The underlying libraries are creating and > > > using threads. But what happens when a non-threaded application loads a > > > thread library via dlopen() (which is the case here)? Here's the stack > > > trace I see: > > > > In that case you're going to have to link the application > > to a threads library. > > I had another thought based on your comments. Since -pthread does the > right thing in -CURRENT, why don't we make that the default > PTHREAD_LIBS? Why do we explicitly link to -lpthread when that causes > shared libs to be linked to threading libraries? If we did -pthread > universally, this problem would go away because ORBit would do the right > thing in the non-threaded case. I thought your example above was creating threads behind the scenes (in the library). That would either require linking the library with -lpthread or every application that used it with -lpthread. Actually, if the library is dynamically loaded, then you still need to explicitly link the application with the threads library (or else libc is going to get confused). I think most of the problem is that our synchronization types are private to each threads library. For FreeBSD-6, we'll change that and have the synchronization types uniformly defined so that libc can see them the same way that the threads library sees them. Perhaps pthread_t will also have to be uniformly defined. So a mutex initialized by libc can be used by libpthread... I don't have a problem with PTHREAD_LIBS being changed to -pthread. I don't know if that will actually solve your particular problem, but it would probably solve other problems and make it easier to mix'n match thread libraries with applications that use the same shared libraries. -- Dan Eischen