Search code examples
c++cwinapimsvcrtcrt

Calling CRT from system spawned thread


System uses Create{Remote}Thread instead of _beginthread for callbacks like ServiceMain, RegisterServiceCtrlHandlerEx, HandlerRoutine (SetConsoleCtrlHandler), etc. Does it mean that it is unsafe to call statically linked CRT from these threads?


Solution

  • In modern (UCRT based) runtime _beginthread{ex} doesn't do any initialization. It only provide minor services like preventing module from unloading while thread is running and optionally initialize WinRT (RoInitialize).