[FFmpeg-cvslog] pthread: Fix deadlock during thread initialization

Derek Buitenhuis git at videolan.org
Mon Oct 14 00:11:43 CEST 2013


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Thu Oct 10 11:05:40 2013 -0400| [eb90a2091ffb94d8c29aaa5ff50f4192520254fc] | committer: Derek Buitenhuis

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 <derek.buitenhuis at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eb90a2091ffb94d8c29aaa5ff50f4192520254fc
---

 libavcodec/pthread.c  |    3 ++-
 libavfilter/pthread.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index f4795f3..b0d9e27 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -152,7 +152,8 @@ static void* attribute_align_arg worker(void *v)
             if (c->current_job == thread_count + c->job_count)
                 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) {
diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index a4f45c8..17e8e7b 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) {



More information about the ffmpeg-cvslog mailing list