Skip to content
Snippets Groups Projects
Commit dd699a1b authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

worker pool: fix worker_pool_wait()

The jobs are removed from the task queue and executed afterwards,
cannot synchronize on the queue only.
parent d7c328d5
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ struct worker_pool {
pthread_cond_t wake;
bool terminating; /*!< Is the pool terminating? .*/
int running; /*!< Number of running threads. */
worker_queue_t tasks;
};
......@@ -67,11 +68,13 @@ static int worker_main(dthread_t *thread)
}
assert(task->run);
pool->running += 1;
pthread_mutex_unlock(&pool->lock);
task->run(task);
pthread_mutex_lock(&pool->lock);
pool->running -= 1;
pthread_cond_broadcast(&pool->wake);
}
......@@ -175,7 +178,7 @@ void worker_pool_wait(worker_pool_t *pool)
}
pthread_mutex_lock(&pool->lock);
while (!EMPTY_LIST(pool->tasks.list)) {
while (!EMPTY_LIST(pool->tasks.list) || pool->running > 0) {
pthread_cond_wait(&pool->wake, &pool->lock);
}
pthread_mutex_unlock(&pool->lock);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment