From eb90a2091ffb94d8c29aaa5ff50f4192520254fc Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Thu, 10 Oct 2013 11:05:40 -0400 Subject: pthread: Fix deadlock during thread initialization Sometimes, if pthread_create() failed, then pthread_cond_wait() could accidentally be called in the worker threads after the uninit function had already called pthread_cond_broadcast(), leading to a deadlock. Don't call pthread_cond_wait() if c->done is set. Signed-off-by: Derek Buitenhuis --- libavfilter/pthread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index a4f45c82cd..17e8e7b20f 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -73,7 +73,8 @@ static void* attribute_align_arg worker(void *v) if (c->current_job == nb_threads + c->nb_jobs) pthread_cond_signal(&c->last_job_cond); - pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); + if (!c->done) + pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); our_job = self_id; if (c->done) { -- cgit v1.2.3