[Gc] race? leads to segfault in GC_suspend_all's call to pthread_kill

Jim Meyering jim at meyering.net
Mon May 9 23:50:08 PDT 2011

Andy Wingo wrote:

> On Fri 06 May 2011 16:00, Jim Meyering <jim at meyering.net> writes:
>> I had had to explicitly GC_register two threads, but had not arranged
>> for them to be unregistered:
>>     https://thread.gmane.org/gmane.comp.lib.iwhd.devel/552
>> Unregistering, as required, solved the problem.
> Whoa, good one!  Thanks for the note, that was interesting.

Thanks.  I wondered if I missed something obvious
in the documentation for GC_register_my_thread, went back
and read its comment and didn't see anything.  Considering
the penalty I incurred for not reading about the companion
function (GC_unregister_my_thread), I suggest this note of warning:

2011-05-10  Jim Meyering  <meyering at redhat.com>

	* include/gc.h (GC_register_my_thread): Add a note of warning:
	if you use GC_register_my_thread to register a thread, you must
	be sure to unregister it with GC_unregister_my_thread.
	Otherwise, your application will fail in a hard-to-diagnose manner.
	E.g., https://thread.gmane.org/gmane.comp.lib.iwhd.devel/552

Index: include/gc.h
RCS file: /cvsroot/bdwgc/bdwgc/include/gc.h,v
retrieving revision 1.86
diff -u -p -r1.86 gc.h
--- include/gc.h	7 Apr 2011 20:35:46 -0000	1.86
+++ include/gc.h	10 May 2011 06:42:38 -0000
@@ -1051,6 +1051,9 @@ GC_API void * GC_CALL GC_call_with_stack
   /* GC_use_threads_discovery() is called at start-up.  Except for the  */
   /* latter case, the explicit call is normally required for threads    */
   /* created by third-party libraries.                                  */
+  /* CAUTION: if you call GC_register_my_thread from a thread, T,       */
+  /* you must ensure that T calls GC_unregister_my_thread before        */
+  /* termination.                                                       */
   GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *);

   /* Unregister the current thread.  Only an explicitly registered      */

More information about the Gc mailing list