Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: David Butenhof <David.Butenhof@hp.com>
Subject: Re: dlopen and threaded libraries
Date: Fri, 06 Dec 2002 08:25:03 -0500	[thread overview]
Message-ID: <nm1I9.17$Vh6.235573@news.cpqcorp.net> (raw)
In-Reply-To: u65u7zrve.fsfYB8X@earthlink.net

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 ]---/


  reply	other threads:[~2002-12-06 13:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-05 18:24 dlopen and threaded libraries qpong
2002-12-06  4:44 ` Paul Pluzhnikov
2002-12-06 13:25   ` David Butenhof [this message]
2002-12-07  0:04     ` Paul Pluzhnikov
2002-12-09 13:45       ` David Butenhof
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox