0

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?

jhourback
  • 4,381
  • 4
  • 26
  • 31
  • 1
    https://stackoverflow.com/questions/10205543/saving-gmon-out-before-killing-a-process solve your problem? – Yakk - Adam Nevraumont Apr 22 '21 at 19:56
  • I thought that would not work because `_mcleanup` is not thread-safe, or at least, cannot be run concurrently with threads being profiled. – jhourback Apr 22 '21 at 20:05
  • Did you try it? Also, consider halting your process except for the main thread, and then doing that cleanup. When I do something similar, I'll often have 2 threads working on the problem; one is attempting to make progress, the other is waking up other threads until the first one can make progress then halting them. The goal is to get the other threads to *not* be blocking in (say) a malloc mutex. It doesn't always work, but so long as it usually works it is good enough for debugging. – Yakk - Adam Nevraumont Apr 22 '21 at 20:11

0 Answers0