curl-library
Re: resolver thread deadlock during Windows DLL attach
Date: Tue, 1 Jan 2008 22:25:32 +0000
Mohun Biswas wrote:
> So presumably starting a new thread from DllMain isn't allowed. In fact
> I just found this in MSDN about DllMain:
>
> "Access to the entry point is serialized by the system on a process-wide
> basis. Threads in DllMain hold the loader lock so no additional DLLs can
> be dynamically loaded or initialized."
You have to be very careful with DllMain. A lot of things don't work
properly from DLL_PROCESS_ATTACH, usually deadlocking but other subtle
bugs are possible too. (Detaching is even worse).
Unlike modern Unix, where it's safe to do most things during DLL
initialisation and finalisation, because those phases are kept
separate from the actual loading, on Windows it isn't safe.
In particular, initialising Winsock from DllMain doesn't always work
(because it might load some Winsock DLLs), depending on the version of
Windows (and Winsock, and third party network products), so even if
you use an IP address, or _synchronous_ DNS resolution, it's not
guaranteed to work on all Windows versions.
-- Jamie
Received on 2008-01-02