aboutsummaryrefslogtreecommitdiff
path: root/src/thread_pool.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-19 17:43:15 +0100
committergingerBill <bill@gingerbill.org>2021-08-19 17:43:15 +0100
commitac6cc5191aed17bdedbe4162d250359616c34286 (patch)
tree2ec83d3c338850492d7657fbc02dc01ab8182783 /src/thread_pool.cpp
parent38841dd46e6bb5879200c0a8e2f879c8cfa005d6 (diff)
Make `ThreadPool.is_running` atomic
Diffstat (limited to 'src/thread_pool.cpp')
-rw-r--r--src/thread_pool.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp
index 738ef19b6..b375d410a 100644
--- a/src/thread_pool.cpp
+++ b/src/thread_pool.cpp
@@ -11,10 +11,10 @@ struct WorkerTask {
struct ThreadPool {
- BlockingMutex mutex;
- Semaphore sem_available;
- std::atomic<i32> processing_work_count;
- bool is_running;
+ BlockingMutex mutex;
+ Semaphore sem_available;
+ std::atomic<i32> processing_work_count;
+ std::atomic<bool> is_running;
gbAllocator allocator;
@@ -74,7 +74,7 @@ void thread_pool_start(ThreadPool *pool) {
}
void thread_pool_join(ThreadPool *pool) {
- pool->is_running = false;
+ pool->is_running.store(false);
semaphore_post(&pool->sem_available, cast(i32)pool->thread_count);
@@ -153,7 +153,7 @@ void thread_pool_wait_to_process(ThreadPool *pool) {
THREAD_PROC(worker_thread_internal) {
ThreadPool *pool = cast(ThreadPool *)thread->user_data;
- while (pool->is_running) {
+ while (pool->is_running.load()) {
semaphore_wait(&pool->sem_available);
WorkerTask task = {};