From fd959fcbe543159fb3e8bad990ab712470cbecef Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Mon, 1 Jan 2024 13:06:22 -0500 Subject: join should be called explicitly --- src/thread_pool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/thread_pool.cpp') diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index c3c8743..b5be8fc 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -59,10 +59,12 @@ void inline PkeThreads_JoinAll_Inner(ThreadPool &tp) { } void inline PkeThreads_Reset_Inner(ThreadPool &tp) { + tp.mutex.lock(); tp.maxJobQueueCount = 0; tp.completedCount = 0; tp.jobQueue->Resize(0); tp.threads->Resize(0); + tp.mutex.unlock(); } bool inline PkeThreads_Enqueue_Inner(ThreadPool &tp, std::packaged_task *job) { @@ -108,7 +110,6 @@ void inline PkeThreads_Shutdown_Inner(ThreadPool &tp) { tp.isPaused = false; tp.jobQueue->Resize(0); tp.mutex.unlock(); - PkeThreads_JoinAll_Inner(tp); } ThreadPoolHandle PkeThreads_Init(uint8_t threadCount, uint8_t maxQueueCount, MemBucket *bkt) { @@ -182,6 +183,7 @@ void PkeThreads_Shutdown(ThreadPoolHandle handle) { auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex]; PkeThreads_Shutdown_Inner(*tp); + PkeThreads_JoinAll_Inner(*tp); } void PkeThreads_Teardown(ThreadPoolHandle handle) { @@ -189,6 +191,7 @@ void PkeThreads_Teardown(ThreadPoolHandle handle) { auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex]; PkeThreads_Shutdown_Inner(*tp); + PkeThreads_JoinAll_Inner(*tp); PkeThreads_Reset_Inner(*tp); Pke_Delete *>>(tp->jobQueue, tp->bkt); Pke_Delete>(tp->threads, tp->bkt); -- cgit v1.2.3