|
Boost : |
From: Roland (roland.schwarz_at_[hidden])
Date: 2004-07-29 01:43:02
On Thu, 29 Jul 2004 00:24:33 +0200 Bronek Kozicki <brok_at_[hidden]> wrote:
> You do not need to worry about local thread data for CRT, at least if
> you use MSVC. Here is explanation: your library B contains function
> DllMain, and it's called just when library got loaded, right? Wrong.
Wrong. I assumed nothing about how B is packaged.
To be more precise I Assume static lib (no DLL). And I am linking
statically to c-runtime.
> you linked with CRT (no matter which one - statically or dynamically
> linked, multi- or single-threaded, with debug symbols or without), your
> entry point is actually _DllMainCRTStartup
Wrong. The CRT exhibits mainCRTStartup (which is also the entrypoint
specified in the PE header for the exe.) If, and only if you are mapping
additional DLL's into your process, their entry points (usually specified
by the linker as DllMainCRTSTartup) their entry point functions are
called. (Process/Thread Attach/Detach)
mainCRTStartup initializes the lib, and calls your main in turn.
> You may find this function in CRT sources (if you installed it together
> with MSVC). In multi-threaded, statically linked version of CRT this
> function will indirectly call TlsAlloc (or actually FlsAlloc - if
> present in "kernel32.dll", at least in CRT delivered with MSVC71).
I don't believe so. TlsAlloc is called from within mainCRTStartup for
the main thread. (Not from DllMainCRTStartUp.)
> .... You are concerned that thread started with CreateThread (or
> whatever other API different than "blessed" _beginthread) might not
> contain valid CRT data in it's local storage. It's true, but CRT runtime
> will receive DLL_THREAD_ATTACH notifications. It will arrive to
> _DllMainCRTStartup if you linked CRT statically,
How should this ever work? When you link the CRT statically there is
no chance of even exposing DllMainCRTStartup! You may only assign
_one_ entrypoint into your executable, and this is already mainCRTStartup.
I already have experimented with this, because the documentation
is vague on when the entry of an exe is getting called. It says something
about that it is getting called on thread attach/detach also. But nope.
It really is not.
The main problem is that when linking your external A which is calling on
you. You cannot be sure your c-runtime is on the correct thread, except
it has been created with _beginthread of the CRT.
Give it a try. Set a breakpoint to your entry function while statically linked.
I bet you will never arrive there :-(
Roland
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk