From 574a90a7c3a2a75ba01324a79fa7e70152efc3eb Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sun, 25 Aug 2019 20:54:47 +0200 Subject: [PATCH] multithreading: close windows thread handle before releasing exit_barrier in thread_cleanup Fixes out of memory errors when creating lots of threads on windows, joining them and then again creating many threads (see e.g. the atomic-incf/decf tests). --- src/c/threads/process.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/c/threads/process.d b/src/c/threads/process.d index 6af0de5c9..673ce89e9 100755 --- a/src/c/threads/process.d +++ b/src/c/threads/process.d @@ -206,12 +206,12 @@ thread_cleanup(void *aux) #endif process->process.env = NULL; ecl_unlist_process(process); - mp_barrier_unblock(3, process->process.exit_barrier, @':disable', ECL_T); - ecl_set_process_env(NULL); - if (env) _ecl_dealloc_env(env); #ifdef ECL_WINDOWS_THREADS CloseHandle(process->process.thread); #endif + mp_barrier_unblock(3, process->process.exit_barrier, @':disable', ECL_T); + ecl_set_process_env(NULL); + if (env) _ecl_dealloc_env(env); AO_store_release((AO_t*)&process->process.phase, ECL_PROCESS_INACTIVE); }