From 239ced8731a29bb2865953e43bffc6b5ce078dc2 Mon Sep 17 00:00:00 2001 From: kalsprite Date: Wed, 19 Aug 2026 12:09:20 -0700 Subject: [PATCH] thread_pool: an exiting worker must not leave published --- src/thread_pool.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index a0afbd269..0ffce8046 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -252,7 +252,14 @@ gb_internal THREAD_PROC(thread_pool_thread_proc) { // if we've done all our work, and there's nothing to steal, go to sleep pool->tasks_available.store(Someone_Waiting); - if (!pool->running) { break; } + if (!pool->running) { + // do not leave the word published on the way out: a worker still on its way to + // futex_wait would sleep on it, and the destroyer does not broadcast again once it + // has committed to its first join + pool->tasks_available.store(Nobody_Waiting); + futex_broadcast(&pool->tasks_available); + break; + } futex_wait(&pool->tasks_available, Someone_Waiting); main_loop_continue:;