I can't call std::exit from an arbitrary thread (or via a signal handler), because other still-running threads will experience undefined behavior (typically, a segfault).
Normally, to exit the program, I would use std::quick_exit, but that doesn't produce the gmon.out file.
So is there a way to produce the gmon.out file?