From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,fea4b5bf798159bd X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-12-06 05:25:54 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!news.compaq.com!news.cpqcorp.net!53ab2750!not-for-mail From: David Butenhof Subject: Re: dlopen and threaded libraries Newsgroups: comp.unix.tru64 References: <194637fd.0212051024.7129e9f0@posting.google.com> User-Agent: KNode/0.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Message-ID: Date: Fri, 06 Dec 2002 08:25:03 -0500 NNTP-Posting-Host: 16.31.48.112 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 1039180307 16.31.48.112 (Fri, 06 Dec 2002 05:11:47 PST) NNTP-Posting-Date: Fri, 06 Dec 2002 05:11:47 PST Organization: Hewlett-Packard Company Xref: archiver1.google.com comp.unix.tru64:9217 Paul Pluzhnikov wrote: > quenton.pongracz@consulting.fujitsu.com (qpong) writes: > >> Can dlopen be used to dynamically link to a threaded library at >> runtime? > > Yes, *provided* the executable doing the dlopen() was itself built > with threads ... > >> The documentation seems to suggest that this is not supported. >> According to the Tru64 UNIX Guide to DECthreads, >> Section A.8 (Dynamic Activation) >> "Dynamic activation of the DECthreads run-time environment, or of code >> that depends on DECthreads, is currently not supported." > > Meaning "IF it wasn't active during C runtime startup, it can't > become active later". > >> In practice I know using dlopen works on threaded libraries, why does >> the documentation say this is not supported? As Paul suggests, there are different cases here, and it's not entirely clear what the OP means by "a threaded library". 1) A THREADED application (linked against libpthread) wants to dynamically activate a shared library (that uses threads). No problem, on any platform that supports threads and dlopen. The process is already threaded, all is cool. Of course, all the code needs to be thread-safe, but that's nothing new due to dlopen. 2. A NON-THREADED application (not linked against libpthread) wants to dynamically activate either libpthread.so or another library linked against libpthread.so. No way, no how. On some systems, like Solaris, this is flatly impossible -- the application has already bound to pthread_create() (et. al) entry points in libc, and loading duplicate entry points in libpthread.so won't change that. You simply cannot dynamically make the application threaded. (Well, at least not in any useful way.) Now, we designed our threaded library to allow for dynamic activation (of the thread library) on both Tru64 UNIX and OpenVMS. And on OpenVMS Alpha it might actually even work, though I wouldn't bet on it. On OpenVMS VAX and on Tru64 UNIX, however, we encountered certain "issues". Like, for example, that the C runtime (and other system libraries) "cheat" to determine, at initialization time (when loaded) whether the process is "threaded"... and they have no mechanism to re-evaluate that decision later. So while you can dynamically add the thread library to the process, and it may even seem to work, this is sheer accident and you're living on borrowed time and the statistical quantum goodwill of the entropic universe... (Hint: this is not a good idea.) Since libc was not about to change that "optimization", and since the general industry frowns upon the entire idea of dynamically making a process threaded, we gradually decided to back off on the whole issue. In fact, I recently got around to making changes in the Guide to DECthreads to make it more clear that (and why) it doesn't work. (For V5.1B.) > AFAIK, AIX is the only UNIX system that supports non-threaded exe > suddenly becoming multi-threaded. Really? Are you sure about that? Intriguing, if so, since IBM was the principal force in The Open Group arguing against supporting dynamic activation. And they had some good arguments, too. Perhaps the folks with the good arguments didn't actually talk to the other IBM folks who were off doing it. -- /--------------------[ David.Butenhof@hp.com ]--------------------\ | Hewlett-Packard Company Tru64 UNIX & VMS Thread Architect | | My book: http://www.awl.com/cseng/titles/0-201-63392-2/ | \----[ http://homepage.mac.com/dbutenhof/Threads/Threads.html ]---/