Re: Can a windows DLL have more than one process attached? - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: Can a windows DLL have more than one process attached?
Date
Msg-id 28377.1006889353@sss.pgh.pa.us
Whole thread Raw
In response to Re: Can a windows DLL have more than one process attached?  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
List pgsql-interfaces
"Ross J. Reedstrom" <reedstrm@rice.edu> writes:
>     The FreeLibrary function decrements the reference count of the
>     loaded dynamic-link library (DLL) module.
> So it's doing the reference counting.

Yeah, but what increments the reference count?  I could believe the code
was okay if it did LoadLibraryEx (which presumably increments the count)
on *every* attach call, but it does that only once, whereas it'll do
FreeLibrary on each detach.

However, we may have worse problems.

> It is not safe to call FreeLibrary or LoadLibraryEx from DllMain.

This looks ugly, although I'm not sure if it's really a problem for us.
I don't see how our pointing to netmsg could create a dependency loop.

I'm also wondering just exactly how Microsoft expects one DLL to be able
to safely reference another, if it's unsafe to call FreeLibrary during
detach --- what else are you supposed to do, leak the reference count?

If this is a problem, a possible answer is not to try to cache the
netmsg reference at all, but just to load and unload that DLL at the
single point where it's used.  Since we only use it to translate
socket error reports, there's probably no big performance penalty
involved to do it that way.
        regards, tom lane


pgsql-interfaces by date:

Previous
From: "Ross J. Reedstrom"
Date:
Subject: Re: Can a windows DLL have more than one process attached?
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: Can a windows DLL have more than one process attached?