Date: Tue, 16 Jul 2002 23:56:21 +0100 (BST) From: Richard Tobin <richard@cogsci.ed.ac.uk> To: FreeBSD-gnats-submit@FreeBSD.org Subject: misc/40671: pthread_cancel doesn't remove thread from condition queue Message-ID: <200207162256.XAA27938@rhymer.cogsci.ed.ac.uk>
next in thread | raw e-mail | index | archive | help
>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 <stdio.h>
#include <stdlib.h>
#include <pthread.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207162256.XAA27938>
