diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 9e0ff02..1d0123b 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -335,8 +335,12 @@ fn unregister(noalias self: *ThreadPool, noalias maybe_thread: ?*Thread) void { fn join(self: *ThreadPool) void { // Wait for the thread pool to be shutdown() then for all threads to enter a joinable state - self.join_event.wait(); - const sync: Sync = @bitCast(self.sync.load(.monotonic)); + var sync: Sync = @bitCast(self.sync.load(.monotonic)); + if (!(sync.state == .shutdown and sync.spawned == 0)) { + self.join_event.wait(); + sync = @bitCast(self.sync.load(.monotonic)); + } + assert(sync.state == .shutdown); assert(sync.spawned == 0);