threads: during abrupt thread-exit, cleanup anyways (#48223)
Closes #47590 (pthread_cancel still forbidden though, since async mode
will corrupt or deadlock the process, and synchronously tested with
cancelation disabled whenever this is a lock is just a slow
implementation of a boolean)
Refs #47201 (only deals with thread exit, not other case where this is
an issue, like cfunction exit and gc-safe-leave)
May help #46537, by blocking jl_wake_libuv before uv_library_shutdown,
and other tweaks to GC mode. For example, avoiding:
[4011824] signal (6.-6): Aborted
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
uv__async_send at /workspace/srcdir/libuv/src/unix/async.c:198
uv_async_send at /workspace/srcdir/libuv/src/unix/async.c:73
jl_wake_libuv at /data/vtjnash/julia1/src/jl_uv.c:44 [inlined]
JL_UV_LOCK at /data/vtjnash/julia1/src/jl_uv.c:64 [inlined]
ijl_iolock_begin at /data/vtjnash/julia1/src/jl_uv.c:72
iolock_begin at ./libuv.jl:48 [inlined]
_trywait at ./asyncevent.jl:140
wait at ./asyncevent.jl:155 [inlined]
profile_printing_listener at /data/vtjnash/julia1/usr/share/julia/stdlib/v1.10/Profile/src/Profile.jl:39
jfptr_YY.3_58617 at /data/vtjnash/julia1/usr/lib/julia/sys.so (unknown line)
_jl_invoke at /data/vtjnash/julia1/src/gf.c:2665 [inlined]
ijl_apply_generic at /data/vtjnash/julia1/src/gf.c:2866
jl_apply at /data/vtjnash/julia1/src/julia.h:1870 [inlined]
start_task at /data/vtjnash/julia1/src/task.c:1093
Aborted
Fixes #37400