DL_PROCESS_DETACH does not correctly operate WaitForSingleObject
I'm writing DLL.
I call the 1st function, inside it I create thread:
hThread = CreateThread(NULL, 0, MyThreadFunction, ...);
I'd like to finish thread, I'm in the 2nd function:
StopMyThread(hThread); //моя фукнция WaitForSingleObject(hThread, INFINITE); CloseHandle(hThread);
Everything works correctly.
Now I want to close thread if the program that uses the dll calls FreeLibrary. For this, in dllmain, I'm processing DL_PROCESS_DETACH. I'm writing the same code as the 2nd function, but it's on WaitForSingleObject(hThread, INFINITE).
Why is this happening?
Not all functions can be safely generated inside
DllMain♪ If the rule has been violated, a dead-lock is just your case.
This can be read in greater detail. https://msdn.microsoft.com/ru-ru/library/windows/desktop/dn633971(v=vs.85).aspx#general_best_practices ♪