[Gc] Problem with GC on FreeBSD

Petter Urkedal urkedal at nbi.dk
Thu Apr 19 10:05:29 PDT 2012


I think I found the bug which makes disclaim_test fail.  The bug is also
reproducible using the regular GC_malloc if the library is compiled with
threads and --enable-gc-assertions, and the line

    GC_ASSERT(GC_is_thread_tsd_valid(tsd));

is commented out from thread_local_alloc.c.  I attach a brewed down
version on disclaim_test.c which uses GC_malloc along with the change to
thread_local_alloc.c needed to unveil the bug.  I tried git-bisect to
located the offending commit, but this seems to go as far back as I was
able to compile, which includes 3c50a689ca85f4fe56afbc8da9e894c4cc3af845
(gc7.0alpha5 tarball import).

The issue is that GC_check_tls goes though the thread-local structures
of other threads.  So, it seems GC_check_tls picks up an object from the
free list which is just about to be unlinked and returned to the caller
by another thread.  Therefore the issue is only seen when assertions are
enabled.  On the other hand the locking done by
GC_is_thread_tsd_valid(tsd) seems sufficient to hide the issue, even
though it does not surround the actual unlinking of the free list.  This
can be verified by replacing the "GC_is_thread_tsd_valid(tsd)" call with
"LOCK(); UNLOCK();"

Ivan, Hans: Any suggestion what's the best way to fix this?


More information about the Gc mailing list