I'm trying to understand what the difference is between CreateThread and _beginthreadex and why calling DisableThreadLibraryCalls only prevents threads installed with _beginthreadex from executing.
I have a project which is a DLL, an old DLL, this is a win32 dll and I am tasked with porting it to win64. One thing that tripped me up was a call in DLLMain to DisableThreadLibraryCalls.
My threads were installed with _beginthreadex, the body of the threads was never being executed cause of the call to DisableThreadLibraryCalls. Once I removed this, the threads were working correctly.
Now I've found that other threads in the same DLL are started with CreateThread, I then thought was the call to DisableThreadLibraryCalls there to prevent these threads from executing so I put it back and found that the threads created with CreateThread are executed regardless of if DisableThreadLibraryCalls is present or not but threads created with _beginthreadex are disabled.
Why? I can't find anything on:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682579(v=vs.85).aspx
That describes why this is happening.
CreateThread() is a Windows native API for creating threads while _beginthread() and _beginthreadex() are part of C runtime library and are intended to make it easier to manage thread creation, but they still internally have to call CreateThread().
Your own answer is wrong because there is no explicit checking for enable/disable involved in C runtime.
Instead, C runtime library uses DLL_THREAD_ATTACH and DLL_THREAD_DETACH callbacks to manage thread local storage so it should not be surprising that disabling those callbacks by calling DisableThreadLibraryCalls() is preventing C runtime thread management functions from working correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With