[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    valgrind/coregrind
From:       Julian Seward <jseward () acm ! org>
Date:       2005-03-21 20:11:03
Message-ID: 20050321201103.10CE95F8 () office ! kde ! org
[Download RAW message or body]

CVS commit by jseward: 


Patch from Jeremy: modify the handling of sys_get_ppid so as to
resolve deadlocks of threaded programs at exit under LinuxThreads.

If the master thread has already exited, and it is this thread's
parent, then force getppid to return 1 (init) rather than the real
ppid, so that it thinks its parent has exited.  This is necessary
because the master thread is artificially kept alive by V until all
other threads have exited, even after it asks to exit.  If any other
thread is waiting for the master thread to exit, and is checking for
that event by polling with get_ppid, it will never observe the master
thread exiting, and so will never itself exit.  But since the master
thread is waiting for all others to exit, we get a deadlock.

This patch adjusts sys_get_ppid so it answers "yes, the master thread
has exited" once the master thread has done sys_exit, even if in fact
it is still alive.  That makes observations from get_ppid consistent
with the exit-state of threads and breaks the deadlock.


  M +10 -0     vg_syscalls.c   1.262
  M +1 -1      x86-linux/syscalls.c   1.28


--- valgrind/coregrind/vg_syscalls.c  #1.261:1.262
@@ -2290,4 +2290,14 @@ PRE(sys_getppid, 0)
 }
 
+POST(sys_getppid)
+{
+   /* If the master thread has already exited, and it is this thread's
+      parent, then force getppid to return 1 (init) rather than the
+      real ppid, so that it thinks its parent has exited. */
+   if (VG_(threads)[VG_(master_tid)].os_state.lwpid == SYSRES &&
+       VG_(is_exiting)(VG_(master_tid)))
+      SYSRES = 1;
+}
+
 PRE(sys_gettid, 0)
 {

--- valgrind/coregrind/x86-linux/syscalls.c  #1.27:1.28
@@ -775,5 +775,5 @@ const struct SyscallTableEntry VGA_(sysc
    //   (__NR_ustat,             sys_ustat)           // 62 SVr4 -- deprecated
    GENXY(__NR_dup2,              sys_dup2),           // 63
-   GENX_(__NR_getppid,           sys_getppid),        // 64
+   GENXY(__NR_getppid,           sys_getppid),        // 64
 
    GENX_(__NR_getpgrp,           sys_getpgrp),        // 65


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic