aboutsummaryrefslogtreecommitdiff
path: root/src/thread_pool.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-26 22:28:09 +0100
committergingerBill <bill@gingerbill.org>2021-08-26 22:28:09 +0100
commitf973d271cf41daa06d060f4c0e4f68effb253c68 (patch)
tree3c4005068da70abc449da2698570281cf134a89d /src/thread_pool.cpp
parent4625b25287d41948a0ae393c49619d9b909bc51c (diff)
Add mutex around `condition_broadcast`
Diffstat (limited to 'src/thread_pool.cpp')
-rw-r--r--src/thread_pool.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp
index ed3a065e0..fc65110fe 100644
--- a/src/thread_pool.cpp
+++ b/src/thread_pool.cpp
@@ -44,8 +44,10 @@ void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count
}
void thread_pool_destroy(ThreadPool *pool) {
+ mutex_lock(&pool->mutex);
pool->stop = true;
condition_broadcast(&pool->task_cond);
+ mutex_unlock(&pool->mutex);
for_array(i, pool->threads) {
Thread *t = &pool->threads[i];
@@ -128,7 +130,9 @@ void thread_pool_wait(ThreadPool *pool) {
thread_pool_do_task(task);
if (--pool->ready == 0) {
+ mutex_lock(&pool->mutex);
condition_broadcast(&pool->task_cond);
+ mutex_unlock(&pool->mutex);
}
}
}
@@ -153,7 +157,9 @@ THREAD_PROC(thread_pool_thread_proc) {
thread_pool_do_task(task);
if (--pool->ready == 0) {
+ mutex_lock(&pool->mutex);
condition_broadcast(&pool->task_cond);
+ mutex_unlock(&pool->mutex);
}
}
} \ No newline at end of file