浏览代码

fix: make pool_finish not hang when pool_start is not called

Bruno Panuto 2 月之前
父节点
当前提交
6874a4cdb0
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      core/thread/thread_pool.odin

+ 14 - 0
core/thread/thread_pool.odin

@@ -120,6 +120,20 @@ pool_join :: proc(pool: ^Pool) {
 
 	yield()
 
+	unstarted_count: int
+	for t in pool.threads {
+		flags := intrinsics.atomic_load(&t.flags)
+		if .Started not_in flags {
+			unstarted_count += 1
+		}
+	}
+
+	// most likely the user forgot to call `pool_start`
+	// exit here, so we don't hang forever
+	if len(pool.threads) == unstarted_count {
+		return
+	}
+
 	started_count: int
 	for started_count < len(pool.threads) {
 		started_count = 0