LIU Hao wrote: > 在 2026-8-28 09:55, Kirill Makurin 写道: >> >> This Microsoft article[1] says that you should _never_ call `CreateThread` >> from `DllMain`: >> >> ``` >> Call CreateThread. Creating a thread can work if you do not synchronize with >> other threads, but it is risky. >> ``` >> >> Given the nature of `_beginthread[ex]` functions, I think this also applies >> to them. > > That's 'should never' and isn't 'shall never'. Because the limitation exists > doesn't necessarily mean > that a DLL can't create a thread upon `DLL_PROCESS_ATTACH`.
That is fair point. Still, I think if there'll be no better solution to avoid potential deadlock in this `_beginthreadex` emulation, we can simply document that under no circumstances `_beginthreadex` shall be called from `DllMain` when using crtdll.dll/msvcrt10.dll. I think that most users are more likely to call `CreateThread` rather than `_beginthreadex` from `DllMain`, which can avoid deadlock if used carefully. This is just me thinking aloud. - Kirill Makurin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
