Skip to content

Commit

Permalink
Fix a race condition in vmaf_thread_pool_wait.
Browse files Browse the repository at this point in the history
There may still be work in the queue but n_working=0 before the vmaf_thread_pool_runner loop fetches another job in the queue.  When calling vmaf_thread_pool_wait (and not stopping), we will still want to drain the queue. So only exit the wait loop when n_working = 0 && head == nullptr
  • Loading branch information
nbirkbeck authored and kylophone committed Sep 20, 2021
1 parent 116ea97 commit db7e336
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libvmaf/src/thread_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ int vmaf_thread_pool_wait(VmafThreadPool *pool)
if (!pool) return -EINVAL;

pthread_mutex_lock(&(pool->queue.lock));
while((!pool->stop && pool->n_working) || (pool->stop && pool->n_threads))
while((!pool->stop && (pool->n_working || pool->queue.head)) ||
(pool->stop && pool->n_threads))
pthread_cond_wait(&(pool->working), &(pool->queue.lock));
pthread_mutex_unlock(&(pool->queue.lock));
return 0;
Expand Down

0 comments on commit db7e336

Please sign in to comment.