[Gc] Bug in Win32 logging

Ben Hutchings ben.hutchings at businesswebsoftware.com
Mon Sep 5 11:36:11 PDT 2005


We have occasionally seen the GC apparently deadlock when attempting to 
write to its log on Win32 while the world is stopped. I believe that 
this can happen if one of the the suspended threads holds the write 
mutex. I think this can be fixed by a change along these lines:

--- gc6.5/win32_threads.c.orig  2005-04-29 18:04:18.000000000 +0100
+++ gc6.5/win32_threads.c       2005-09-05 19:31:44.201875000 +0100
@@ -233,6 +233,9 @@
 # endif
 }

+/* Defined in misc.c */
+extern CRITICAL_SECTION GC_write_cs;
+
 void GC_stop_world()
 {
   DWORD thread_id = GetCurrentThreadId();
@@ -241,6 +244,7 @@
   if (!GC_thr_initialized) ABORT("GC_stop_world() called before GC_thr_init()");

   GC_please_stop = TRUE;
+  EnterCriticalSection(&GC_write_cs);
   for (i = 0; i <= GC_get_max_thread_index(); i++)
     if (thread_table[i].stack_base != 0
        && thread_table[i].id != thread_id) {
@@ -271,6 +275,7 @@
 #     endif
       thread_table[i].suspended = TRUE;
     }
+  LeaveCriticalSection(&GC_write_cs);
 }

 void GC_start_world()

Ben.



More information about the Gc mailing list