diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-01 13:06:22 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2024-01-01 13:06:22 -0500 |
| commit | fd959fcbe543159fb3e8bad990ab712470cbecef (patch) | |
| tree | 14d5795f7201edc50357576df22a324569a2f5f8 | |
| parent | 3404cd0752ebcad7782ca7863fda0985f478e0a0 (diff) | |
join should be called explicitly
| -rw-r--r-- | src/thread_pool.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
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<void()> *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<DynArray<std::packaged_task<void()> *>>(tp->jobQueue, tp->bkt); Pke_Delete<DynArray<std::thread>>(tp->threads, tp->bkt); |
