[Gc] GC_thread_exit_proc error on win32_threads.c

Tommaso Tagliapietra (EXT VE SYS) tommaso.tagliapietra at enel.it
Tue Jun 6 00:05:38 PDT 2006

All threads are created with PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED attribute and GC_pthread_create. At the end of the start_function of a thread I use a pthread_cleanup_push to call a function that change a flag in a struct, and than a pthread_cleanup_pop(1). 
The last instruction is a pthread_exit because for some reason normal return doesn't free used memory for the thread and program stop sometimes with "Abort: too many threads" (I don't know if this is a problem of the colletor ... I'm not expert on threads ... so I put this call as last instruction). I'm sure that process reach GC_thread_exit_proc but at the end there's the Segmentation Fault. 
I think GC_thread_exit_proc is the last call performed by the thread, right?

static void cleanupThread(void *thread) {
  ((MyThread*)thread)->flag = THREAD_STATUS_STOP;

static void *runThread(void *thread) {
 void *ret;
  pthread_cleanup_push(cleanupThread, thread);

  //... do some work. Ret is initialized here

  /* Call cleanup thread callback function */
  /* On Cygwin exiting without pthread_exit(ret) cause an abort for
     too may threads */
  return ret;

  ----- Original Message ----- 
  From: Boehm, Hans 
  To: Tommaso Tagliapietra (EXT VE SYS) ; gc at napali.hpl.hp.com 
  Sent: Tuesday, June 06, 2006 12:53 AM
  Subject: RE: [Gc] GC_thread_exit_proc error on win32_threads.c

  Can you track this down to a particular instruction that generates the segmentation fault?  This sounds like a possible race in the pthread_cleanup implementation.  Do you use thread cancellation?


    From: gc-bounces at napali.hpl.hp.com [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Tommaso Tagliapietra (EXT VE SYS)
    Sent: Monday, May 29, 2006 2:24 AM
    To: gc at napali.hpl.hp.com
    Subject: [Gc] GC_thread_exit_proc error on win32_threads.c

    In a Pentium4 2.6Ghz with WindowsXP Professional SP2, I have a problem with the release 6.4 of the garbage collector under Cygwin, and probably with other releases of the collector.  It seems that at the end of GC_thread_exit_proc (win32_threads.c module), sometimes my program exit with a Segmentation Fault. I'm sure that there is not my code the problem and probably not the Garbage Collector too. However I've resolved the problem adding a "Sleep(10);" at the end of the function:

    void GC_thread_exit_proc(void *arg)
        GC_thread me = (GC_thread)arg;

          GC_printf2("thread 0x%x(0x%x) called pthread_exit().\n",
                     (int)pthread_self(), GetCurrentThreadId());
    #   endif

        if (me -> flags & DETACHED) {
        } else {
          /* deallocate it as part of join */
          me -> flags |= FINISHED;

    The same problem doesn't not happen into a P4 2Ghz WindowsXP Professional SP2. Same compiler. Why this stupid change works without segmentation fault? Can be some race conditions the reason?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://napali.hpl.hp.com/pipermail/gc/attachments/20060606/af6ea16e/attachment.htm

More information about the Gc mailing list