Merge pull request #1786 from Kelimion/thread_fix

Fix thread pool join.
This commit is contained in:
Jeroen van Rijn
2022-05-13 15:17:08 +02:00
committed by GitHub
+12
View File
@@ -39,6 +39,7 @@ Pool :: struct {
threads: []^Thread, threads: []^Thread,
tasks: [dynamic]Task, tasks: [dynamic]Task,
tasks_done: [dynamic]Task, tasks_done: [dynamic]Task,
} }
@@ -102,9 +103,20 @@ pool_join :: proc(pool: ^Pool) {
yield() 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 { for t in pool.threads {
if .Started in t.flags {
started_count += 1
}
if .Joined not_in t.flags {
join(t) join(t)
} }
}
}
} }
// Add a task to the thread pool. // Add a task to the thread pool.