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.
Showing the changes to libavfilter/pthread.c (1 of 2 files). Show all
Unified · Split
| @@ -73,7 +73,8 @@ static void* attribute_align_arg worker(void *v) · 72 unmodified lines | ||
| 73 | 73 | if (c->current_job == nb_threads + c->nb_jobs) |
| 74 | 74 | pthread_cond_signal(&c->last_job_cond); |
| 75 | 75 | |
| 76 | − pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); | |
| 76 | + if (!c->done) | |
| 77 | + pthread_cond_wait(&c->current_job_cond, &c->current_job_lock); | |
| 77 | 78 | our_job = self_id; |
| 78 | 79 | |
| 79 | 80 | if (c->done) { |