What\'s a better way to start a thread, _beginthread
, _beginthreadx
or CreateThread
?
I\'m trying to determine what are the adv
The other answers fail to discuss the implications of calling a C run-time function that wraps a Win32 API function. This is important when considering DLL loader locking behavior.
Whether or not _beginthread{ex}
does any special C Runtime thread/fiber memory management as the other answers discuss, it is implemented in (assuming dynamic linking to the C run-time) a DLL that processes may not have loaded yet.
It is not safe to call _beginthread*
from DllMain
. I have tested this by writing a DLL loaded using the Windows "AppInit_DLLs" feature. Calling _beginthreadex (...)
instead of CreateThread (...)
causes a LOT of important parts of Windows to stop functioning during bootup as the DllMain
entry-point deadlocks waiting for the loader lock to be released in order to perform certain initialization tasks.
Incidentally, this is also why kernel32.dll has a lot of overlapping string functions that the C run-time also does -- use those from DllMain
to avoid the same sort of situation.