Skip to content

Commit

Permalink
opj_thread_pool_setup(): fix infinite waiting if a thread creation fa…
Browse files Browse the repository at this point in the history
…iled
  • Loading branch information
rouault committed Oct 18, 2018
1 parent 0e6a555 commit cd900d9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/openjp2/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads)
tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function,
&(tp->worker_threads[i]));
if (tp->worker_threads[i].thread == NULL) {
opj_mutex_destroy(tp->worker_threads[i].mutex);
opj_cond_destroy(tp->worker_threads[i].cond);
tp->worker_threads_count = i;
bRet = OPJ_FALSE;
break;
Expand All @@ -732,7 +734,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads)
/* Wait all threads to be started */
/* printf("waiting for all threads to be started\n"); */
opj_mutex_lock(tp->mutex);
while (tp->waiting_worker_thread_count < num_threads) {
while (tp->waiting_worker_thread_count < tp->worker_threads_count) {
opj_cond_wait(tp->cond, tp->mutex);
}
opj_mutex_unlock(tp->mutex);
Expand Down

0 comments on commit cd900d9

Please sign in to comment.