From owner-freebsd-stable Fri Mar 24 14:18:29 2000 Delivered-To: freebsd-stable@freebsd.org Received: from mail.hcisp.net (Stargate.hcisp.net [208.60.89.18]) by hub.freebsd.org (Postfix) with SMTP id 8679637B57A for ; Fri, 24 Mar 2000 14:18:20 -0800 (PST) (envelope-from tim@mysql.com) Received: (qmail 12569 invoked from network); 24 Mar 2000 22:24:27 -0000 Received: from modem9.hcisp.net (HELO threads.polyesthetic.msg) (208.60.89.75) by stargate.hcisp.net with SMTP; 24 Mar 2000 22:24:27 -0000 Received: (qmail 37534 invoked by uid 1001); 24 Mar 2000 22:17:16 -0000 From: "Thimble Smith" Date: Fri, 24 Mar 2000 17:17:16 -0500 To: freebsd-stable@freebsd.org Subject: pthread_kill() not killing thread Message-ID: <20000324171716.E37030@threads.polyesthetic.msg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include #include #include #include #include #include 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