[Gc] RE: Thread creation deadlock with libgc
Wed, 18 Jun 2003 16:08:34 -0700
[I included the gc mailing list, since this is an important bug, which I vaguely recall
Thanks very much for the small test case. I was able to reproduce the problem
and track it down. It turns out the FINISHED flag in the GC's thread structure was
being set prematurely. This could cause GC_pthread_detach to deallocate the
thread structure (because it thought the thread was finished) before the thread
itself was really done with it.
I believe the following patch (consisting of a one line deletion) solves the problem.
But this is subtle enough that additional testing would be very useful. I will include
this in 6.2 unless I hear of problems.
--- pthread_support.c.orig 2003-06-18 15:17:30.000000000 -0700
+++ pthread_support.c 2003-06-18 16:10:38.000000000 -0700
@@ -1175,7 +1175,6 @@
GC_printf1("Finishing thread 0x%x\n", pthread_self());
me -> status = result;
- me -> flags |= FINISHED;
/* Cleanup acquires lock, ensuring that we can't exit */
/* while a collection that thinks we're alive is trying to stop */
I believe aix_irix_threads.c also needs the corresponding deletion.
> -----Original Message-----
> From: Dick Porter [mailto:email@example.com]
> Sent: Monday, June 16, 2003 10:56 AM
> To: Hans_Boehm@hp.com
> Subject: Thread creation deadlock with libgc
> I've been seeing a deadlock during thread creation that I have traced
> back to libgc (I tested the latest version, 6.2alpha6).
> With the attached test program, compiled with "gcc -DGC_LINUX_THREADS
> -Wall -g -o gc-thread gc-thread.c -lpthread -lgc" I always eventually
> get a segfault, or a deadlock if I run in gdb. The backtrace
> is always
> (gdb) bt
> #0 0x4009387e in sigsuspend () from /lib/libc.so.6
> #1 0x40029879 in __pthread_wait_for_restart_signal ()
> from /lib/libpthread.so.0
> #2 0x4002aee1 in sem_wait@@GLIBC_2.1 () from /lib/libpthread.so.0
> #3 0x4004e705 in GC_pthread_create (new_thread=0xbffffb24, attr=0x0,
> start_routine=0x8048650 <thread_func>, arg=0x0) at
> #4 0x0804869a in main (argc=1, argv=0xbffffb94) at gc-thread.c:20
> Without libgc, the test will run until I get bored.
> This is on a linux/x86 box, glibc 2.2.5, linuxthreads pthreads.
> - Dick