[Gc] RE: Thread creation deadlock with libgc

Dan Bonachea bonachea@cs.berkeley.edu
Thu, 19 Jun 2003 03:31:07 -0700


Proposed one-line fix to aix_irix_threads.c successfully tested on both AIX 
and IRIX, with gcc and native compilers.

However, I don't think it was ever a problem in aix_irix_threads.c, because 
those ports do not currently capture the pthread_detach call - threads created 
in the detached state are handled correctly (as are joined threads), but 
threads which are detached after creation using pthread_detach will have their 
GC_threads entry silently leaked.

This should ideally be fixed (with a solution similar to pthreads_support.c), 
although it doesn't apply to our project's usage scenario so I'm not planning 
to lose sleep over it... that is, unless someone desperately wants it fixed 
and is willing to supply relevant test code (pthread_detach is never called in 
the current GC tests). This bug could only ever be a problem in codes that 
frequently detach threads after creation and terminate them.

Dan

At 04:08 PM 6/18/2003, Boehm, Hans wrote:
>[I included the gc mailing list, since this is an important bug, which I 
>vaguely recall
>chasing before.]
>
>Dick -
>
>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.
>
>Hans
>
>--- 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());
>  #endif
>      me -> status = result;
>-    me -> flags |= FINISHED;
>      pthread_cleanup_pop(1);
>      /* 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:dick@ximian.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
> > pthread_support.c:1256
> > #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
> >
> >
>_______________________________________________
>Gc mailing list
>Gc@linux.hpl.hp.com
>http://linux.hpl.hp.com/cgi-bin/mailman/listinfo/gc