Re: Can a windows DLL have more than one process attached?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Can a windows DLL have more than one process attached?
Date: 2001-11-27 19:29:13
Message-ID: 28377.1006889353@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

"Ross J. Reedstrom" <reedstrm(at)rice(dot)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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 2001-11-27 19:35:53 Re: Can a windows DLL have more than one process attached?
Previous Message Ross J. Reedstrom 2001-11-27 19:26:09 Re: Can a windows DLL have more than one process attached?