浏览代码

Merge pull request #1786 from Kelimion/thread_fix

Fix thread pool join.
Jeroen van Rijn 3 年之前
父节点
当前提交
286f782e5e
共有 1 个文件被更改,包括 14 次插入2 次删除
  1. 14 2
      core/thread/thread_pool.odin

+ 14 - 2
core/thread/thread_pool.odin

@@ -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,8 +103,19 @@ pool_join :: proc(pool: ^Pool) {
 
 
 	yield()
 	yield()
 
 
-	for t in pool.threads {
-		join(t)
+	// 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 {
+				started_count += 1
+			}
+			if .Joined not_in t.flags {
+				join(t)
+			}
+		}
 	}
 	}
 }
 }