Skip to content

Commit afa6c90

Browse files
Brooooooklynclaude
andcommitted
set _mi_process_is_initialized before mi_process_setup_auto_thread_done
439dc27 moved `mi_process_setup_auto_thread_done` into `mi_process_init_once` so it runs after `mi_thread_init` and can associate the current theap with the thread-done key. It now runs before `_mi_process_is_initialized = true`, and with `MI_TLS_RECURSE_GUARD` (always on for `MI_TLS_MODEL_LOCAL` on macOS) `_mi_theap_default()` still returns `_mi_theap_empty` at that point. The new `mi_assert_internal(mi_theap_is_initialized(theap))` fires in debug builds; release builds skip the association, so the first thread's theap is again never passed to `_mi_thread_done`. Repro (macOS): `cmake -DCMAKE_BUILD_TYPE=Debug -DMI_TLS_MODEL=LOCAL` then `./mimalloc-test-api` aborts at process init on v3.5.2 and passes on v3.5.1. Same with `-DMI_TLS_RECURSE_GUARD=ON` on Linux. Set the flag before `mi_process_setup_auto_thread_done`; the theap is fully initialized by then. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016srh5svTkqfW21zGcU6ht9
1 parent 636510a commit afa6c90

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/init.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ static void mi_process_init_once(void) {
560560
// the following can potentially allocate (on freeBSD for pthread keys)
561561
_mi_tls_slots_init(); // pthread key create
562562
_mi_thread_locals_init(); // pthread key create
563-
mi_process_setup_auto_thread_done(); // after the above mi_thread_init so it can add the current theap
564-
_mi_process_is_initialized = true;
563+
_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`
564+
mi_process_setup_auto_thread_done(); // after the above mi_thread_init so it can add the current theap
565565

566566
#if defined(_WIN32) && defined(MI_WIN_INIT_USE_FLS)
567567
// On windows, when building as a static lib the FLS cleanup happens to early for the main thread.

0 commit comments

Comments
 (0)