Expand comment on 'FLS early cleanup avoidance' in mi_process_init()

This commit is contained in:
Frank Richter 2022-01-02 13:40:59 +01:00
parent f456bc75ea
commit 2b19908057

View file

@ -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