Date: Thu, 13 Jul 2023 09:54:08 -0700
On Thursday, 13 July 2023 09:35:23 PDT Thiago Macieira via Std-Proposals
wrote:
> _exit() and _Exit() don't run any functions registered with atexit(), so
> they're basically a call to TerminateProcess(). At that point, all threads
> except the current one disappear (problem 2(d)), and the Win32 system starts
> unloading the DLLs. As it does that, it'll call DllMain() on each DLL and
> this causes the C++ runtime built into each of those DLLs to run their
> static destructors.
Did I mention this affects abort() too, and thus std::terminate()?
The MS documentation[1] even explicitly says it fails to conform to the
standard:
> For Windows compatibility reasons, when abort calls _exit, it may invoke the
> Windows ExitProcess API, which in turn allows DLL termination routines to
> run. Destructors aren't run in the executable, but the same may not be true
> of DLLs loaded in the executable's process space. This behavior doesn't
> strictly conform to the C++ standard.
That's why we had to ban the use of abort() in Qt and instead provided our own
qAbort() [2].
[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/abort
[2] https://github.com/qt/qtbase/blob/
56a776da406c710de3dbf8832b7c20add2e4ca3a/src/corelib/global/qglobal.cpp#L136-
L163
wrote:
> _exit() and _Exit() don't run any functions registered with atexit(), so
> they're basically a call to TerminateProcess(). At that point, all threads
> except the current one disappear (problem 2(d)), and the Win32 system starts
> unloading the DLLs. As it does that, it'll call DllMain() on each DLL and
> this causes the C++ runtime built into each of those DLLs to run their
> static destructors.
Did I mention this affects abort() too, and thus std::terminate()?
The MS documentation[1] even explicitly says it fails to conform to the
standard:
> For Windows compatibility reasons, when abort calls _exit, it may invoke the
> Windows ExitProcess API, which in turn allows DLL termination routines to
> run. Destructors aren't run in the executable, but the same may not be true
> of DLLs loaded in the executable's process space. This behavior doesn't
> strictly conform to the C++ standard.
That's why we had to ban the use of abort() in Qt and instead provided our own
qAbort() [2].
[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/abort
[2] https://github.com/qt/qtbase/blob/
56a776da406c710de3dbf8832b7c20add2e4ca3a/src/corelib/global/qglobal.cpp#L136-
L163
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Software Architect - Intel DCAI Cloud Engineering
Received on 2023-07-13 16:54:10