From owner-freebsd-bugs Tue Jul 16 16: 0:16 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 08D9937B400 for ; Tue, 16 Jul 2002 16:00:07 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6280043E81 for ; Tue, 16 Jul 2002 16:00:06 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g6GN06JU096888 for ; Tue, 16 Jul 2002 16:00:06 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g6GN06vW096887; Tue, 16 Jul 2002 16:00:06 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E2DAE37B401 for ; Tue, 16 Jul 2002 15:56:26 -0700 (PDT) Received: from rhymer.cogsci.ed.ac.uk (rhymer.cogsci.ed.ac.uk [129.215.144.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id CE25743E3B for ; Tue, 16 Jul 2002 15:56:25 -0700 (PDT) (envelope-from richard@cogsci.ed.ac.uk) Received: (from richard@localhost) by rhymer.cogsci.ed.ac.uk (8.9.3/8.9.3) id XAA27938 for FreeBSD-gnats-submit@freebsd.org; Tue, 16 Jul 2002 23:56:21 +0100 (BST) Message-Id: <200207162256.XAA27938@rhymer.cogsci.ed.ac.uk> Date: Tue, 16 Jul 2002 23:56:21 +0100 (BST) From: Richard Tobin To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: misc/40671: pthread_cancel doesn't remove thread from condition queue Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 40671 >Category: misc >Synopsis: pthread_cancel doesn't remove thread from condition queue >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jul 16 16:00:05 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Richard Tobin >Release: FreeBSD 4.6-RELEASE i386 >Organization: Bugs-R-Us >Environment: System: 4.6-RELEASE FreeBSD (But present in all recent releases, I think.) Pthreads library. Observed in xine video player, but there is probably a bug in xine itself that is provoking it. >Description: When a pthread is cancelled, it is not removed from any condition queue that it is in. This causes Fatal error '_waitq_remove: Not in queue' when the condition is later signalled. >How-To-Repeat: See attached program p3.c. >Fix: It is probably sufficient to add cond_queue_remove(*cond, _thread_run); after "if(interrupted != 0)" in pthread_cond_wait, but I'm not certain whether that is the best fix. --- p3.c begins here --- #include #include #include void *run(void *argp); pthread_mutex_t mutex; pthread_t thread; pthread_cond_t condition; int main(int argc, char **argv) { struct sched_param sp; void *retval; int i; pthread_mutex_init(&mutex, 0); pthread_cond_init(&condition, 0); pthread_create(&thread, 0, run, 0); usleep(1000); pthread_cancel(thread); usleep(1000); pthread_cond_signal(&condition); return 0; } void *run(void *argp) { pthread_mutex_lock(&mutex); pthread_cond_wait(&condition, &mutex); return 0; } --- p3.c ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message