Date: Fri, 24 Mar 2000 17:17:16 -0500 From: "Thimble Smith" <tim@mysql.com> To: freebsd-stable@freebsd.org Subject: pthread_kill() not killing thread Message-ID: <20000324171716.E37030@threads.polyesthetic.msg>
next in thread | raw e-mail | index | archive | help
Hi. I'm running 4.0-STABLE cvsup'd on Tuesday (21 Mar). It looks like pthread_kill() isn't killing the thread; I could be doing something wrong, of course. Here's the output of my test program: tim:/tmp$ cc -o simple simple.c -pthread tim:/tmp$ ./simple main-thrd: letting test thread start up... test-body: unblocking signal and looping... test-body: sleeping... main-thrd: sleeping... test-body: sleeping... main-thrd: killing test thread... main-thrd: waiting a sec... test-body: sleeping... main-thrd: unblocking TERM signal here... main-thrd: waiting a sec... test-body: sleeping... main-thrd: exiting test-body: sleeping... test-body: sleeping... test-body: sleeping... test-body: sleeping... test-body: returning tim:/tmp$ The TERM signal never gets delivered to the test thread. Here is the code: #include <assert.h> #include <pthread.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> pthread_t test_thread; sigset_t set; void *test_body(void *arg) { int i; fprintf(stderr, "test-body: looping...\n"); /* this SIG_UNBLOCK doesn't have any effect */ /*assert( pthread_sigmask(SIG_UNBLOCK, &set, NULL) == 0);*/ for (i = 0; i < 8; ++i) { fprintf(stderr, "test-body: sleeping...\n"); sleep(1); } fprintf(stderr, "test-body: returning\n"); return NULL; } int main (void) { pthread_attr_t attrs; sigemptyset(&set); sigaddset(&set, SIGTERM); assert( pthread_sigmask(SIG_UNBLOCK, &set, NULL) == 0); assert( pthread_attr_init(&attrs) == 0); assert( pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); assert( pthread_create(&test_thread, &attrs, test_body, NULL) == 0 ); assert( pthread_attr_destroy(&attrs) == 0); fprintf(stderr, "main-thrd: letting test thread start up...\n"); sleep(1); /* I should have this uncommented for a real program, but it doesn't make any difference here - the signal isn't delivered. */ /*assert( pthread_sigmask(SIG_BLOCK, &set, NULL) == 0);*/ fprintf(stderr, "main-thrd: sleeping...\n"); sleep(1); fprintf(stderr, "main-thrd: killing test thread...\n"); assert( pthread_kill(test_thread, SIGTERM) == 0); fprintf(stderr, "main-thrd: waiting a sec...\n"); sleep(1); /* With LinuxThreads, this would cause the program to terminate. But with -stable, this has no effect. */ fprintf(stderr, "main-thrd: unblocking TERM signal here...\n"); assert( pthread_sigmask(SIG_UNBLOCK, &set, NULL) == 0); fprintf(stderr, "main-thrd: waiting a sec...\n"); sleep(1); fprintf(stderr, "main-thrd: exiting\n"); pthread_exit(NULL); /*exit(EXIT_SUCCESS);*/ } The extra pthread_sigmask(SIG_UNBLOCK, &set) that is in test_body() doesn't make any difference. Am I doing something wrong? Or should I file a problem report? Thanks, Tim To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000324171716.E37030>