From ccecdaf04411b65f5badbeaae36f50c9c216d37b Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 3 Oct 2022 21:31:34 +0300 Subject: Fix missing lock while updating GC_in_thread_creation in GC_exit_check (fix of commit 8e6460052) * misc.c [!DONT_USE_ATEXIT && THREADS] (GC_exit_check): Wrap each update of GC_in_thread_creation into LOCK/UNLOCK (but not GC_gcollect call); add comment. --- misc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/misc.c b/misc.c index 8b02f53e..b542819d 100644 --- a/misc.c +++ b/misc.c @@ -766,11 +766,19 @@ GC_API int GC_CALL GC_is_init_called(void) { if (GC_find_leak && !skip_gc_atexit) { # ifdef THREADS + DCL_LOCK_STATE; + + /* GC_in_thread_creation should always be updated holding the */ + /* lock even if we are about to exit. */ + LOCK(); GC_in_thread_creation = TRUE; /* OK to collect from unknown thread. */ - GC_gcollect(); + UNLOCK(); +# endif + GC_gcollect(); +# ifdef THREADS + LOCK(); GC_in_thread_creation = FALSE; -# else - GC_gcollect(); + UNLOCK(); # endif } } -- cgit v1.2.1