bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible bug sighting - exit hang


From: Wolfram Gloger
Subject: Re: possible bug sighting - exit hang
Date: 22 Nov 2001 21:08:45 -0000

Ok, I take it back -- partially.  Changing the 'atfork' handlers so
one can distinguish system- and user handlers seems too complicated.
(I have produced such a patch but it is very long and introduces a new
global function __pthread_atfork_system() for use in malloc.)  I think
the following is preferable.  With this,
pthread_kill_other_threads_np() still precludes any later use of
free(), but I don't care too much about that case...

With this patch, I can run Hui Huang's sample without hangs.

2001-11-22  Wolfram Gloger  <address@hidden>

        * pthread.c (pthread_onexit_process): Don't call free
        after threads have been asynchronously terminated.

        * manager.c (pthread_handle_exit): Surround cancellation
        of threads with __flockfilelist()/__funlockfilelist().

--- linuxthreads/pthread.c.orig Thu Aug 16 03:50:05 2001
+++ linuxthreads/pthread.c      Thu Nov 22 17:07:14 2001
@@ -793,7 +793,9 @@
     if (self == __pthread_main_thread)
       {
        waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
-       free (__pthread_manager_thread_bos);
+       /* Since all threads have been asynchronously terminated
+           (possibly holding locks), free cannot be used any more.  */
+       /*free (__pthread_manager_thread_bos);*/
        __pthread_manager_thread_bos = __pthread_manager_thread_tos = NULL;
       }
   }
--- linuxthreads/manager.c.orig Mon Jul 23 19:54:13 2001
+++ linuxthreads/manager.c      Thu Nov 22 17:40:16 2001
@@ -883,6 +902,12 @@
   pthread_descr th;
   __pthread_exit_requested = 1;
   __pthread_exit_code = exitcode;
+  /* A forced asynchronous cancellation follows.  Make sure we won't
+     get stuck later in the main thread with a system lock being held
+     by one of the cancelled threads.  Ideally one would use the same
+     code as in pthread_atfork(), but we can't distinguish system and
+     user handlers there.  */
+  __flockfilelist();
   /* Send the CANCEL signal to all running threads, including the main
      thread, but excluding the thread from which the exit request originated
      (that thread must complete the exit, e.g. calling atexit functions
@@ -899,6 +924,7 @@
        th = th->p_nextlive) {
     waitpid(th->p_pid, NULL, __WCLONE);
   }
+  __fresetlockfiles();
   restart(issuing_thread);
   _exit(0);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]