* dlopen and threaded libraries
@ 2002-12-05 18:24 qpong
2002-12-06 4:44 ` Paul Pluzhnikov
0 siblings, 1 reply; 5+ messages in thread
From: qpong @ 2002-12-05 18:24 UTC (permalink / raw)
Can dlopen be used to dynamically link to a threaded library at
runtime?
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."
In practice I know using dlopen works on threaded libraries, why does
the documentation say this is not supported?
Any insight would be greatly apreciated.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dlopen and threaded libraries
2002-12-05 18:24 dlopen and threaded libraries qpong
@ 2002-12-06 4:44 ` Paul Pluzhnikov
2002-12-06 13:25 ` David Butenhof
0 siblings, 1 reply; 5+ messages in thread
From: Paul Pluzhnikov @ 2002-12-06 4:44 UTC (permalink / raw)
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?
AFAIK, AIX is the only UNIX system that supports non-threaded exe
suddenly becoming multi-threaded.
Cheers,
--
In order to understand recursion you must first understand recursion.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dlopen and threaded libraries
2002-12-06 4:44 ` Paul Pluzhnikov
@ 2002-12-06 13:25 ` David Butenhof
2002-12-07 0:04 ` Paul Pluzhnikov
0 siblings, 1 reply; 5+ messages in thread
From: David Butenhof @ 2002-12-06 13:25 UTC (permalink / raw)
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 ]---/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dlopen and threaded libraries
2002-12-06 13:25 ` David Butenhof
@ 2002-12-07 0:04 ` Paul Pluzhnikov
2002-12-09 13:45 ` David Butenhof
0 siblings, 1 reply; 5+ messages in thread
From: Paul Pluzhnikov @ 2002-12-07 0:04 UTC (permalink / raw)
David Butenhof <David.Butenhof@hp.com> writes:
> Paul Pluzhnikov wrote:
> > AFAIK, AIX is the only UNIX system that supports non-threaded exe
> > suddenly becoming multi-threaded.
>
> Really? Are you sure about that?
Perhaps I am reading more than what is written?
http://www-1.ibm.com/servers/esdd/pdfs/aix_ll.pdf (page 23):
With the introduction of AIX 4.3, all system libraries are now
inherently thread-enabled. libc contains a mechanism whereby
it can detect whether the pthreads environment must be enabled,
and will perform all initialization required to support pthreads
at program start-up, as well as at the time that libpthreads
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
is introduced into a running process via dynamic loading. This
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
means that a program can be constructed in a manner that does not
take advantage of threads, but may become a threaded program due
to a module dependency hierarchy that incorporates the pthreads
library. It is advantageous to consider support for threads when
an application is built.
Cheers,
--
In order to understand recursion you must first understand recursion.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dlopen and threaded libraries
2002-12-07 0:04 ` Paul Pluzhnikov
@ 2002-12-09 13:45 ` David Butenhof
0 siblings, 0 replies; 5+ messages in thread
From: David Butenhof @ 2002-12-09 13:45 UTC (permalink / raw)
Paul Pluzhnikov wrote:
> David Butenhof <David.Butenhof@hp.com> writes:
>
>> Paul Pluzhnikov wrote:
>> > AFAIK, AIX is the only UNIX system that supports non-threaded exe
>> > suddenly becoming multi-threaded.
>>
>> Really? Are you sure about that?
>
> Perhaps I am reading more than what is written?
> http://www-1.ibm.com/servers/esdd/pdfs/aix_ll.pdf (page 23):
>
> With the introduction of AIX 4.3, all system libraries are now
> inherently thread-enabled. libc contains a mechanism whereby
> it can detect whether the pthreads environment must be enabled,
> and will perform all initialization required to support pthreads
> at program start-up, as well as at the time that libpthreads
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> is introduced into a running process via dynamic loading. This
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> means that a program can be constructed in a manner that does not
> take advantage of threads, but may become a threaded program due
> to a module dependency hierarchy that incorporates the pthreads
> library. It is advantageous to consider support for threads when
> an application is built.
Well. Interesting. That certainly sounds pretty unambiguous.
On the other hand, that is all essentially what we tried to do. The problem
is that while the system libraries (e.g., libc) are all "thread enabled",
some (e.g. libc ;-) ) are not capable of REEVALUATING that decision once
it's been made. There's nothing in the AIX documentation extract you've
shown that actually SAYS anything different. (Though it clearly IMPLIES
that it ought to be able to reevaluate dynamically.)
Still, someone in AIX clearly wanted to try and thought it was useful. Which
I suppose means nothing more than that it wasn't designed by the same
people who were arguing in The Open Group. ;-)
--
/--------------------[ 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 ]---/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-12-09 13:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-05 18:24 dlopen and threaded libraries qpong
2002-12-06 4:44 ` Paul Pluzhnikov
2002-12-06 13:25 ` David Butenhof
2002-12-07 0:04 ` Paul Pluzhnikov
2002-12-09 13:45 ` David Butenhof
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox