diff --git a/src/init.c b/src/init.c index 30445a58c..9b0ded5b5 100644 --- a/src/init.c +++ b/src/init.c @@ -560,8 +560,8 @@ static void mi_process_init_once(void) { // the following can potentially allocate (on freeBSD for pthread keys) _mi_tls_slots_init(); // pthread key create _mi_thread_locals_init(); // pthread key create - mi_process_setup_auto_thread_done(); // after the above mi_thread_init so it can add the current theap - _mi_process_is_initialized = true; + _mi_process_is_initialized = true; // before `mi_process_setup_auto_thread_done` so `_mi_theap_default` returns the current theap with `MI_TLS_RECURSE_GUARD` + mi_process_setup_auto_thread_done(); // after the above mi_thread_init so it can add the current theap #if defined(_WIN32) && defined(MI_WIN_INIT_USE_FLS) // On windows, when building as a static lib the FLS cleanup happens to early for the main thread.