From 81316155d4838392e8462a92bcac3eebe9acd0c7 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 5 May 2023 12:08:17 -0700 Subject: [PATCH] Avoid running `init_config()` more than once per process Windows runs `DllMain` multiple times; when new threads are started, for instance. We want to run our `DllMain()` implementation only during process attachment (e.g. when the first thread loads it). --- src/libblastrampoline.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libblastrampoline.c b/src/libblastrampoline.c index 5c27adb..381df01 100644 --- a/src/libblastrampoline.c +++ b/src/libblastrampoline.c @@ -406,6 +406,9 @@ void * _win32_self_handle; BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD code, void *reserved) { if (code == DLL_PROCESS_ATTACH) { _win32_self_handle = (void *)hModule; + } else { + // We do not want to run our initialization more than once per process. + return TRUE; } #else __attribute__((constructor)) void init(void) {