[runtime]Split thread unregistration in two steps, one with no locks, one with locks taken. Fixes #15916.
In order allow for arbitrary code in the profiler callback we must invoke it without
holding any runtime leaf lock - this happens quite frequently with sdb as it tries to
suspend the world on those callbacks.
So thread shutdown is now split in two phases, first one that does the no-locks part
where the thread remains suspendable afterwards and then onewith locks taken where we
do the final cleanup and final shutdown.