Date: Wed, 1 May 2002 11:06:21 -0700 (PDT) From: Archie Cobbs <archie@dellroad.org> To: Archie Cobbs <archie@dellroad.org> Cc: "Jeroen Ruigrok/asmodai" <asmodai@wxs.nl>, Daniel Eischen <eischen@pcnet1.pcnet.com>, freebsd-stable@FreeBSD.ORG Subject: Re: Bug in pthread_cancel() Message-ID: <200205011806.g41I6LF92589@arch20m.dellroad.org> In-Reply-To: <200205011559.g41Fx4Z92027@arch20m.dellroad.org> "from Archie Cobbs at May 1, 2002 08:59:04 am"
next in thread | previous in thread | raw e-mail | index | archive | help
Archie Cobbs writes: > > And the testcase in the PR is solved adequately with it? Below is a program that seems to demonstrate the problem. Note that the thread is canceled before it exits, but it doesn't reach a cancellation point until after it exits. -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-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205011806.g41I6LF92589>