Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 May 2002 11:10:04 -0700 (PDT)
From:      Archie Cobbs <archie@packetdesign.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/37614: libc_r aborts when exiting thread is canceled
Message-ID:  <200205011810.g41IA4Q40474@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/37614; it has been noted by GNATS.

From: Archie Cobbs <archie@packetdesign.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/37614: libc_r aborts when exiting thread is canceled
Date: Wed, 01 May 2002 11:07:46 -0700

 Test case below.
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com
 
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sched.h>
 #include <pthread.h>
 #include <err.h>
 
 static void
 thread_cleanup(void *arg)
 {
         sched_yield();
         printf("Thread: executing cleanup...\n");
         pthread_testcancel();
 }
 
 static void *
 thread_main(void *arg)
 {
         pthread_cleanup_push(thread_cleanup, NULL);
         printf("Thread: sleeping 1 second...\n");
         sleep(1);
         printf("Thread: sending SIGTERM...\n");
         kill(getpid(), SIGTERM);
         sched_yield();
         printf("Thread: exiting...\n");
         return (NULL);
 }
 
 int
 main(int argc, char **argv)
 {
         pthread_t tid;
         sigset_t sigs;
         int sig;
 
         /* Spawn thread */
         printf("Main: spawning thread...\n");
         if ((errno = pthread_create(&tid, NULL, thread_main, NULL)) != 0)
                 err(1, "pthread_create");
 
         /* Wait for signal */
         sigemptyset(&sigs);
         sigaddset(&sigs, SIGINT);
         sigaddset(&sigs, SIGTERM);
         if (sigprocmask(SIG_BLOCK, &sigs, NULL) == -1)
                 err(1, "sigprocmask");
         printf("Main: waiting for signal...\n");
         if (sigwait(&sigs, &sig) == -1)
                 err(1, "sigwait");
 
         /* Cancel thread */
         printf("Main: canceling thread...\n");
         pthread_cancel(tid);
 
         /* Done */
         usleep(500);
         printf("Main: exiting...\n");
         return (0);
 }

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205011810.g41IA4Q40474>