From 7e0c359f993bb595ac794518bf882414133cd1c2 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 13 May 2022 15:03:40 +0200 Subject: [PATCH 1/2] Fix thread pool join. --- core/thread/thread_pool.odin | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/thread/thread_pool.odin b/core/thread/thread_pool.odin index af80da9aa..2ff3a6a52 100644 --- a/core/thread/thread_pool.odin +++ b/core/thread/thread_pool.odin @@ -39,6 +39,7 @@ Pool :: struct { threads: []^Thread, + tasks: [dynamic]Task, tasks_done: [dynamic]Task, } @@ -102,8 +103,15 @@ pool_join :: proc(pool: ^Pool) { yield() - for t in pool.threads { - join(t) + started_count: int + for started_count < len(pool.threads) { + started_count = 0 + for t in pool.threads { + if .Started in t.flags { + join(t) + started_count += 1 + } + } } } From 58fc305b11f1f4fb4b5f7de037947f905e05f849 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 13 May 2022 15:11:33 +0200 Subject: [PATCH 2/2] Do a bit less work for pool_join. --- core/thread/thread_pool.odin | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/thread/thread_pool.odin b/core/thread/thread_pool.odin index 2ff3a6a52..840cecfec 100644 --- a/core/thread/thread_pool.odin +++ b/core/thread/thread_pool.odin @@ -103,14 +103,18 @@ pool_join :: proc(pool: ^Pool) { yield() + // Because we already stopped the pool, there's no need to take a lock here. + started_count: int for started_count < len(pool.threads) { started_count = 0 for t in pool.threads { if .Started in t.flags { - join(t) started_count += 1 } + if .Joined not_in t.flags { + join(t) + } } } }