History

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.

Derek Buitenhuis committed 13 years ago

Commit eb90a201 parent c9ef6b02 files · +4 −2Browse files

Unified · Split

2 files
  1. libavcodec/pthread.c +2 −1
  2. libavfilter/pthread.c +2 −1
libavcodec/pthread.c+2−1
@@ -152,7 +152,8 @@ static void* attribute_align_arg worker(void *v) · 151 unmodified lines
152152 if (c->current_job == thread_count + c->job_count)
153153 pthread_cond_signal(&c->last_job_cond);
154154
155− pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
155+ if (!c->done)
156+ pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
156157 our_job = self_id;
157158
158159 if (c->done) {
libavfilter/pthread.c+2−1
@@ -73,7 +73,8 @@ static void* attribute_align_arg worker(void *v) · 72 unmodified lines
7373 if (c->current_job == nb_threads + c->nb_jobs)
7474 pthread_cond_signal(&c->last_job_cond);
7575
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);
7778 our_job = self_id;
7879
7980 if (c->done) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t