Pump hazard pointer queue in unregister_thread while thread is still alive. (#4183)
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Thu, 22 Dec 2016 16:41:04 +0000 (11:41 -0500)
committerGitHub <noreply@github.com>
Thu, 22 Dec 2016 16:41:04 +0000 (11:41 -0500)
Some of the destructors (for example mono_jit_info_table_free) may try to take
a lock, which requires that the current thread should be attached.

mono/utils/mono-threads.c

index 9605ad826f29fda56f22f1a73d646a8204fc6a23..e8893039fbf2eb2a89a828c4c4b7607f6a50ac44 100644 (file)
@@ -426,6 +426,9 @@ unregister_thread (void *arg)
        g_assert (mono_thread_info_is_current (info));
        g_assert (mono_thread_info_is_live (info));
 
+       /* Pump the HP queue while the thread is alive.*/
+       mono_thread_hazardous_try_free_some ();
+
        small_id = info->small_id;
 
        /* We only enter the GC unsafe region, as when exiting this function, the thread
@@ -481,8 +484,6 @@ unregister_thread (void *arg)
 
        /*now it's safe to free the thread info.*/
        mono_thread_hazardous_try_free (info, free_thread_info);
-       /* Pump the HP queue */
-       mono_thread_hazardous_try_free_some ();
 
        mono_thread_small_id_free (small_id);