From: John Maddock (john_at_[hidden])
Date: 2004-07-31 06:06:55
> I was also always under the same impression, but reading the MSDN docs on
> CreateThread it sounds a bit less restrictive than I remembered:
> "A thread in an executable that is linked to the static C run-time library
> (CRT) should use _beginthread and _endthread for thread management rather
> than CreateThread and ExitThread. Failure to do so results in small memory
> leaks when the thread calls ExitThread. Another work around is to link the
> executable to the CRT in a DLL instead of the static CRT. Note that this
> memory leak only occurs from a DLL if the DLL is linked to the static CRT
> and a thread calls the DisableThreadLibraryCalls function. Otherwise, it
> safe to call CreateThread and ExitThread from a thread in a DLL that links
> to the static CRT."
I never knew that, in fact I never knew that DisableThreadLibraryCalls
function existed at all, thanks for the pointer!
> Also, in what way doesn't exception handling work if the thread wasn't
> created using __beginthread? I tried the following snippet under
> which ran silently (yes, under debug config):
> I don't pretend that I understand all subtleties of exception handling,
> the above at least _seems_ to work ok.
You could be right, actually my memory is a little hazy on this one, but I
think the problem with Borland C++ rather than MSVC++ which I *think*
implements exception handling on top of structured exceptions (which should
always work), where as other compiles do their own thing and rely on some
global state to work correctly.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk