Fix #7970, #2161, unfix #551

Establish the reachability of threads before weak pointers.  Hence a
deadlocked thread can keep a weak pointer alive and prevent it from
being finalized early.  However, an reference from the finalizer of a
weak pointer will no longer prevent a thread from being considered
deadlocked (#551).  To keep the thread alive in that situation you
need to use a StablePtr.

See comments on #7970 and in the code for more details.