From owner-freebsd-stable Wed May 1 11:15:10 2002 Delivered-To: freebsd-stable@freebsd.org Received: from InterJet.dellroad.org (adsl-63-194-81-26.dsl.snfc21.pacbell.net [63.194.81.26]) by hub.freebsd.org (Postfix) with ESMTP id D45F437B404 for ; Wed, 1 May 2002 11:15:02 -0700 (PDT) Received: from arch20m.dellroad.org (arch20m.dellroad.org [10.1.1.20]) by InterJet.dellroad.org (8.9.1a/8.9.1) with ESMTP id LAA69968; Wed, 1 May 2002 11:06:21 -0700 (PDT) Received: (from archie@localhost) by arch20m.dellroad.org (8.11.6/8.11.6) id g41I6LF92589; Wed, 1 May 2002 11:06:21 -0700 (PDT) (envelope-from archie) From: Archie Cobbs Message-Id: <200205011806.g41I6LF92589@arch20m.dellroad.org> Subject: Re: Bug in pthread_cancel() In-Reply-To: <200205011559.g41Fx4Z92027@arch20m.dellroad.org> "from Archie Cobbs at May 1, 2002 08:59:04 am" To: Archie Cobbs Date: Wed, 1 May 2002 11:06:21 -0700 (PDT) Cc: "Jeroen Ruigrok/asmodai" , Daniel Eischen , freebsd-stable@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL88 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 #include #include #include #include #include #include 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