summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2016-12-08 17:53:58 -0800
committerJohn Stebbins <[email protected]>2016-12-17 07:28:51 -0800
commit1364ef08ec8035b2af77f214a4406e5300fb0ff2 (patch)
tree5d157b90351173400f8aa5363e8a20afe542e7e6 /libhb
parent66af0167b40262f2aaf55bfe368f4125b7535020 (diff)
potential fix for hard to reproduce crash
Diffstat (limited to 'libhb')
-rw-r--r--libhb/work.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libhb/work.c b/libhb/work.c
index 7d43ce4c5..1cfb08bb1 100644
--- a/libhb/work.c
+++ b/libhb/work.c
@@ -1734,6 +1734,9 @@ static void do_job(hb_job_t *job)
}
// Wait for the thread of the last work object to complete
+ // Note that other threads may still be running even though the
+ // last thread has exited. So we must be careful with the sequence
+ // of closing threads below.
w = hb_list_item(job->list_work, hb_list_count(job->list_work) - 1);
w->die = job->die;
hb_thread_close(&w->thread);
@@ -1762,14 +1765,20 @@ cleanup:
}
}
- /* Close work objects */
- while ((w = hb_list_item(job->list_work, 0)))
+ // Close work objects
+ // A work thread can use data created by another work thread's init.
+ // So close all work threads before closing thread data.
+ for (i = 0; i < hb_list_count(job->list_work); i++)
{
- hb_list_rem(job->list_work, w);
+ w = hb_list_item(job->list_work, i);
if (w->thread != NULL)
{
hb_thread_close(&w->thread);
}
+ }
+ while ((w = hb_list_item(job->list_work, 0)))
+ {
+ hb_list_rem(job->list_work, w);
w->close(w);
free(w);
}