Reapply "Ensure the signal handling thread is detached before exiting"

This reverts commit d9269d427e24cbaa887e64e28414f294e5b9f2b5.

PS2 changes to not cleanup the thread list during shutdown:
- When destroying the Runtime (in the rare cases of running ART and
exiting normally) detaching the thread would happen after the thread_list_ was
already destroyed and set to nullptr, meaning we'd segfault on
thread_list_->Unregister.

- Avoid this by not unregistering when we are in
the process of shutting down. The plugin unload (which closes the pipe
and triggers the thread detach) happens after we start the shutdown
process.

Bug: 473643072
Test: atest HeapprofdJavaCtsTest
Test: adb shell 'app_process -classpath /system/framework/incident-helper-cmd.jar /system/bin/ com.android.commands.incident.IncidentHelper  -l run persisted_logs --limit 10MB' 1>/dev/null && echo 'tombstones: ' && adb shell ls -l /data/tombstones
Flag: EXEMPT BUGFIX
Change-Id: I05a9df7ac6a4f6634118791af0f00c8bd81712f0
2 files changed