Commit eb90a209 authored by Derek Buitenhuis's avatar 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: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parent c9ef6b09
...@@ -152,7 +152,8 @@ static void* attribute_align_arg worker(void *v) ...@@ -152,7 +152,8 @@ static void* attribute_align_arg worker(void *v)
if (c->current_job == thread_count + c->job_count) if (c->current_job == thread_count + c->job_count)
pthread_cond_signal(&c->last_job_cond); 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; our_job = self_id;
if (c->done) { if (c->done) {
......
...@@ -73,7 +73,8 @@ static void* attribute_align_arg worker(void *v) ...@@ -73,7 +73,8 @@ static void* attribute_align_arg worker(void *v)
if (c->current_job == nb_threads + c->nb_jobs) if (c->current_job == nb_threads + c->nb_jobs)
pthread_cond_signal(&c->last_job_cond); 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; our_job = self_id;
if (c->done) { if (c->done) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment