diff --git a/src/init/init.cpp b/src/init/init.cpp index 2b5eb9510..82761fc61 100644 --- a/src/init/init.cpp +++ b/src/init/init.cpp @@ -63,5 +63,6 @@ initializer::initializer() { initializer::~initializer() { finalize(); + delete_thread_finalizer_manager(); } } diff --git a/src/util/thread.cpp b/src/util/thread.cpp index 2cfa3bedf..58b92e8ae 100644 --- a/src/util/thread.cpp +++ b/src/util/thread.cpp @@ -108,14 +108,24 @@ public: } }; -static thread_finalizers_manager g_aux; +thread_finalizers_manager * g_aux = nullptr; + +thread_finalizers_manager & get_manager() { + if (!g_aux) + g_aux = new thread_finalizers_manager(); + return *g_aux; +} + +void delete_thread_finalizer_manager() { + delete g_aux; +} void register_thread_finalizer(thread_finalizer fn, void * p) { - g_aux.get_thread_finalizers().emplace_back(fn, p); + get_manager().get_thread_finalizers().emplace_back(fn, p); } void register_post_thread_finalizer(thread_finalizer fn, void * p) { - g_aux.get_post_thread_finalizers().emplace_back(fn, p); + get_manager().get_post_thread_finalizers().emplace_back(fn, p); } void run_thread_finalizers() { @@ -128,6 +138,8 @@ void run_post_thread_finalizers() { LEAN_THREAD_PTR(thread_finalizers, g_finalizers); LEAN_THREAD_PTR(thread_finalizers, g_post_finalizers); +void delete_thread_finalizer_manager() {} + void register_thread_finalizer(thread_finalizer fn, void * p) { if (!g_finalizers) g_finalizers = new thread_finalizers(); diff --git a/src/util/thread.h b/src/util/thread.h index 4dd8d51bd..6d24f83a0 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -207,4 +207,5 @@ void register_post_thread_finalizer(thread_finalizer fn, void * p); void register_thread_finalizer(thread_finalizer fn, void * p); void run_thread_finalizers(); void run_post_thread_finalizers(); +void delete_thread_finalizer_manager(); }