I find myself in a situation in which I need to exit a cross-platform C++ application immediately, without running destructors, and also without causing a crash. How can I do that?
exit(0)
runs the destructors;quick_exit(0)
is not implemented in VC++;abort()
causes a crash;_Exit(0)
does not seem implemented in VC++ (or at least does not appear in MSDN);- the documentation of
_exit(0)
is unclear as to whether it calls destructors – apparently, it calls them under Windows.
I believe that I can use quick_exit
under non-Windows platforms, but I am lacking a solution for VC++.
Clarification (since people ask why I wish to avoid destructors) This is an optimization scenario. I am dealing with a large application that manipulates Gigabytes of RAM, allocated in complex graphs, with several processes, numerous threads, thread-safe reference-counting, watchdogs, etc. The memory management/resource deallocation mechanism is optimized for keeping the application responsive during runtime use and/or monitor possible errors (depending on build flags), but these mechanisms are clearly overkill during shutdown, keeping the CPU very busy for many seconds, draining the battery, etc – long after we are sure that all file descriptors/handles have been closed. This makes users unhappy, so I am experimenting how to improve this, preferably without having to refactor everything.
The call quick_exit
was designed specifically for such scenarios, but isn't supported by VC++. So I'm looking for an alternative for that platform.