Ensure mono_gc_thread_detach is always called. (#47816)
authorJonathan Chambers <joncham@gmail.com>
Fri, 5 Feb 2021 11:31:27 +0000 (06:31 -0500)
committerGitHub <noreply@github.com>
Fri, 5 Feb 2021 11:31:27 +0000 (12:31 +0100)
commit37f1fb9bab1a024d2487f898d2a8fe83e13e761b
tree70155229830888a478790634fd716929bd3dcfe9
parentc7c734e2828119035a4474fa6e74e73769d992db
Ensure mono_gc_thread_detach is always called. (#47816)

The previous logic would not call `mono_gc_thread_detach` for a number of scenarios. One example:
```
start_wrapper
- mono_thread_info_attach - thread is now live in mono threads layer
- start_wrapper_internal
-- mono_thread_attach_internal - mono attached to vm thread layer. GC handle is set via mono_thread_info_set_internal_thread_gchandle
-- mono_thread_detach_internal - detached from vm thread layer. GC handle cleared via call to mono_thread_info_unset_internal_thread_gchandle
- mono_thread_info_exit
-- mono_thread_info_detach
--- unregister_thread
---- thread_detach callback - checks if gc handle is valid and returns if not via mono_thread_info_try_get_internal_thread_gchandle. We've already cleared above so we never call mono_gc_thread_detach.
```

This change ensures `mono_gc_thread_detach` is always called even the GC handle for the thread has already been cleared.
src/mono/mono/metadata/threads.c