2 ms·
On Mac and iOS, this thorny issue is made even worse by some ancient Darwin design choices. When the process is terminated, the main thread executes static dest
by worstspotgain 3y ago
On Mac and iOS, this thorny issue is made even worse by some ancient Darwin design choices. When the process is terminated, the main thread executes static destructors while the other threads are still running. This causes unpredictable exit-time crashes in (typically cross-platform) code that uses static variables with nontrivial destructors.
The solution is to always terminate all threads before exiting. This requires a bit of internal infrastructure that's missing from many projects. If a cross-platform library is being used, it may start its own untracked threads.
On iOS, app processes only terminate in special circumstances. When this issue yields a crash it's (currently) imperceptible to the user. However, it's still tracked in the crash statistics.
- gpderetta 3y agostd::quick_exit
- worstspotgain 3y agoSure, and on many systems there are platform-specific ways of terminating the process. However: - Executing static destructors without crashing is the ideal result. - On Mac, there are factors that make the thread-termination approach preferable, such as using cross-platform libraries or a framework like Qt. - On iOS, none of these apply, as process termination is out of your hands.