Subject: lib/26988: pthread_kill bug
To: None <>
From: Chris Ross <>
List: netbsd-bugs
Date: 09/18/2004 01:50:41
>Number:         26988
>Category:       lib
>Synopsis:       Calling pthread_kill(t_id, 0) of an exited thread returns 0
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 18 05:51:00 UTC 2004
>Originator:     Chris Ross
>Release:        NetBSD 2.0G
System: NetBSD HOSTNAME 2.0G NetBSD 2.0G (HOSTNAME) #1: Mon Jul 26 17:54:57 EDT 2004 cross@HOSTNAME:/data/obj/NetBSD.i386/data/NetBSD/src/sys/arch/i386/compile/SNAFU i386
Architecture: i386
Machine: i386
	Enclosed is a test program that shows the problem.  When a
child thread (started by pthread_create()) returns, or calls 
pthread_exit(), the thread should be dead and removed from the
list of threads maintained by the pthread library.  When remaining
threads call pthread_kill(), sending a signal 0 to the pthread_t
of the exit'ed child thread, it returns 0.  According to my
understanding, and not contradicted by the man page for pthread_kill(),
sending a signal of any sort to a thread no longer in the list
of running threads, should cause an ESRCH error, not 0.
	Compile and run this with -lpthread:
#include <stdio.h>
#include <pthread.h>

void *
thread_func(void *val)
	printf("*CHILD* This is the thread function.\n");
	printf("*CHILD* I slept for 2 seconds, and am now returning...\n");

	int		ret;
	pthread_t	child;

	ret = pthread_create(&child, NULL, thread_func, NULL);
	if (ret != 0) {
		fprintf(stderr, "pthread_create failed: %s", strerror(ret));

	printf("*PARENT* Started child thread.\n");
	sleep(1);	printf("*PARENT* Slept for 1 second.\n");
	sleep(3);	printf("*PARENT* Slept for another 3 seconds.\n");

	ret = pthread_kill(child, 0);
	printf("*PARENT* A pthread_kill of the child thread returned %d.\n",