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

Derek Buitenhuis git at videolan.org
Thu Jan 16 23:26:51 CET 2014


ffmpeg | branch: release/0.10 | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Thu Oct 10 11:05:40 2013 -0400| [48d57650f121d3d9e977832e9006bb334337d921] | committer: Luca Barbato

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>
(cherry picked from commit 1a5a6ac01b0ad2cf3d2128372ea41f3c1cfc2d3f)

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

 libavcodec/pthread.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 64cff43..af1c945 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -206,7 +206,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) {



More information about the ffmpeg-cvslog mailing list