[Top][All Lists]

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

bug fix : Process hangs on thread death (linuxthreads)

From: Nawaaz Ahmed
Subject: bug fix : Process hangs on thread death (linuxthreads)
Date: Mon, 6 May 2002 14:25:11 -0700

Hi Folks,
We have noticed that sometimes when a thread dies (maybe due to a
signal) the process does not exit (but seems to hang). We are running the
latest version (2.2.5 of glibc) on a 2.4.18 basde kernel. Here's the
trace for the manager thread :-

#0  0x400a7aee in sigsuspend () from /lib/libc.so.6
#1  0x4006d6b9 in __pthread_wait_for_restart_signal ()
   from /lib/libpthread.so.0
#2  0x4006f856 in __pthread_alt_lock () from /lib/libpthread.so.0
#3  0x4006be22 in pthread_mutex_lock () from /lib/libpthread.so.0
#4  0x400ecbfb in free () from /lib/libc.so.6
#5  0x4006b4ab in pthread_free () from /lib/libpthread.so.0
#6  0x4006b591 in pthread_exited () from /lib/libpthread.so.0
#7  0x4006b5f9 in pthread_reap_children () from /lib/libpthread.so.0
#8  0x4006ac29 in __pthread_manager () from /lib/libpthread.so.0

Presumably the thread died while holding the malloc lock and the manager
suspends when it tries to acquire the lock to free the thread data. In
pthread_reap_children, we could check the status of the thread (and
exit if necessary) before we clean up by calling pthread_exited().

--- linuxthreads/manager.c      Mon Feb 25 09:17:34 2002
+++ linuxthreads.patched/manager.c      Tue Apr 30 08:14:32 2002
@@ -941,13 +941,18 @@ static void pthread_reap_children(void)
   int status;

   while ((pid = __libc_waitpid(-1, &status, WNOHANG | __WCLONE)) > 0)
-    pthread_exited(pid);
+    /*
+     * check the status of the thread before cleaning up after it -
+     * if the thread has exited holding a lock (e.g. in malloc)
+     * it may not be possible to clean up
+     */
     if (WIFSIGNALED(status)) {
       /* If a thread died due to a signal, send the same signal to
          all other threads, including the main thread. */
       pthread_kill_all_threads(WTERMSIG(status), 1);
+    pthread_exited(pid);


PS:- Ofcourse we will need to fix our code which presumably is
thrashing the heap :-)

reply via email to

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