On Friday 28 August 2026 11:09:07 LIU Hao wrote: > I'm also wondering why anyone would call prefer `_beginthreadex()` to > `CreateThread()`. Unlike Microsoft CRT, mingw-w64 CRT is linked against > MSVCRT or UCRT DLL, where these functions are almost identical, with similar > parameters and semantics.
CRT applications should always call _beginthread or _beginthreadex, not the CreateThread directly. CreateThread is suitable only when the spawned thread is calling WinAPI function and does not call CRT functions. _beginthread(ex) is initializing thread local storage and redirection of SEH exceptions to registered CRT signal handlers. New CRT libs can initialize thread local storage also on demand, but that means that any CRT function may unexpected crash the whole process because TLS failures. In _beginthread(ex) the is hopefully propagated during the call. And CRT signal handler is part of ISO C signal() functionality. Also in case application is doing static linking (which is not case for mingw-w64, only for msvc) then combination of _beginthreadex and _endthreadex correctly release CRT thread local storage memory. Not calling them cause memory leaks. So basically CRT apps should call CRT _beginthreadex and WinAPI-only apps could call CreateThread. _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
