>Date: 19 May 1999 14:01:06 -0700
>From: Greg Winton <[EMAIL PROTECTED]>
>Subject: Re: Can a shared lib be SysLibLoad()ed twice?
>
>At 12:12 PM 5/19/99 -0700, Jeff Ishaq wrote:
>>I wonder if SysLibLoad() will prevent a second, duplicate 
>instance of a
>>library from being loaded or not.
>>
>SysLibLoad() will fail the second time.
>

Greg, when I looked over the source for SysLibLoad, I didn't see any
mechanism to return failure the second time, which is why I was curious in
the first place.  I actually got off my ass and did some empirical testing
(which I probably should have done before wasting bandwidth, but you know
how that goes!) and I discovered some interesting results I'd like to share.

If I SysLibLoad() my shared library twice, I get two sequential valid
reference numbers.  In addition, both copies of the library have their Sleep
and Wake entry points called upon sleeping and waking.  This implies that
each instance of the library has its own uniqute SysLibTblEntryPtr (this is
implicit in the fact that they each have their own reference number,
really).

This is certainly not the behavior either of us expected.  If I think about
it, though, why not?  I mean, it's not like two instances of the same shared
library will have conflicts over their globals, since they don't HAVE
globals (instead, they each have their own ptr-to-globals-struct).  You
wouldn't even need to use the context pointer mechanism (magic cookies) to
deal with globals between two instances of the same shared library this way,
since each instance has its own unique reference number and thus its own
unique libGlobalsP.

I'm not sure if this is the intended behavior of SysLibLoad(), though.  It
seems a little hairy.

Oh, and one case where you could want to have two instances of a shared
library open is through a sublaunched app.  For example, MyApp opens up
MySharedLib.  Then the user does a 'find', and in MyApp's Find launch code
handler, I might need a new instance of MySharedLib running to get some
services from it.  Though I suppose if your app opened a shared library
already, your app's Find launch code handler should probably be smart enough
to know that.  Hm.

Anyway sorry for asking and then testing, but these results were curious
enough to be documented.

-Jeff Ishaq
The Windward Group

Reply via email to