Skip to content

Commit 439dc27

Browse files
committed
associate process init theap with thread-done key, pr #1393
by @Brooooooklyn
1 parent 3309f1f commit 439dc27

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/init.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ static void mi_thread_theaps_done(mi_tld_t* tld)
446446
static void mi_process_setup_auto_thread_done(void) {
447447
mi_atomic_do_once {
448448
_mi_prim_thread_init_auto_done();
449+
mi_theap_t* theap = _mi_theap_default();
450+
mi_assert_internal(mi_theap_is_initialized(theap));
451+
if (mi_theap_is_initialized(theap)) {
452+
_mi_theap_default_set(theap);
453+
}
449454
}
450455
}
451456

@@ -454,7 +459,7 @@ void mi_thread_done(void) mi_attr_noexcept {
454459
}
455460

456461
void _mi_thread_done(mi_theap_t* _theap_main)
457-
{
462+
{
458463
// NULL can be passed on some platforms
459464
if (_theap_main==NULL) {
460465
_theap_main = _mi_theap_default();
@@ -511,7 +516,6 @@ void _mi_auto_process_init(void) {
511516
os_preloading = false;
512517

513518
mi_process_init();
514-
mi_process_setup_auto_thread_done();
515519

516520
_mi_options_post_init(); // now we can print to stderr
517521
if (_mi_is_redirected()) _mi_verbose_message("malloc is redirected.\n");
@@ -556,6 +560,7 @@ static void mi_process_init_once(void) {
556560
// the following can potentially allocate (on freeBSD for pthread keys)
557561
_mi_tls_slots_init(); // pthread key create
558562
_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
559564
_mi_process_is_initialized = true;
560565

561566
#if defined(_WIN32) && defined(MI_WIN_INIT_USE_FLS)

0 commit comments

Comments
 (0)