From 2b1990805745dad1a7f85c5aa17c2d5dca7903a8 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Sun, 2 Jan 2022 13:40:59 +0100 Subject: [PATCH] Expand comment on 'FLS early cleanup avoidance' in mi_process_init() --- src/init.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index 47aa2b23..19519151 100644 --- a/src/init.c +++ b/src/init.c @@ -494,8 +494,11 @@ void mi_process_init(void) mi_attr_noexcept { _mi_verbose_message("secure level: %d\n", MI_SECURE); mi_thread_init(); #if defined(_WIN32) && !defined(MI_SHARED_LIB) - // When building as a static lib FLS cleanup happens to early for the main thread. - // Make it a no-op and perform it explicitly later. + /* When building as a static lib the FLS cleanup happens to early for the main thread. + * To avoid that set the FLS value for the main thread to NULL; the eventual + * mi_fls_done() execution won't call _mi_thread_done(). + * The latter function is later called explicitly from mi_process_done(). + * See GitHub issue #508 for more background and explanation. */ FlsSetValue(mi_fls_key, NULL); #endif mi_stats_reset(); // only call stat reset *after* thread init (or the heap tld == NULL) @@ -527,7 +530,7 @@ static void mi_process_done(void) { process_done = true; #if defined(_WIN32) && !defined(MI_SHARED_LIB) - // Explicitly clean up main thread + // Explicitly clean up main thread. See comment in mi_process_init() for reason _mi_thread_done(_mi_heap_default); FlsSetValue(mi_fls_key, NULL); // don't call main-thread callback FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208