Subject: proposed fix for pthread_kill() of a zombie thread.
To: None <tech-userlevel@netbsd.org>
From: Chuck Silvers <chuq@chuq.com>
List: tech-userlevel
Date: 10/09/2005 09:10:26
--XWOWbaMNXpFDWE00
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

hi,

I was experimenting with apache's "worker" MPM and I saw that under
heavy load ("ab -c 1000") httpd would die with an internal assertion.
the problem is that the web server was pthread_kill()ing a thread
which had already pthread_exit()ed but had not yet been pthread_join()ed.
a simple test program reproduces this.

the attached patch fixes this by simply ignoring signals sent to
zombie threads.   anyone see any problem with this?

-Chuck

--XWOWbaMNXpFDWE00
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.kill-zombie"

Index: pthread_sig.c
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libpthread/pthread_sig.c,v
retrieving revision 1.39.2.2
diff -u -p -r1.39.2.2 pthread_sig.c
--- pthread_sig.c	12 Aug 2005 06:38:14 -0000	1.39.2.2
+++ pthread_sig.c	9 Oct 2005 15:59:57 -0000
@@ -848,6 +848,9 @@ pthread__kill(pthread_t self, pthread_t 
 		PTQ_REMOVE(target->pt_sleepq, target, pt_sleep);
 		pthread_spinunlock(self, target->pt_sleeplock);
 		break;
+	case PT_STATE_ZOMBIE:
+		pthread_spinunlock(self, &target->pt_statelock);
+		return;
 	default:
 		;
 	}

--XWOWbaMNXpFDWE00--