diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 1d0123b..aec09d7 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -291,6 +291,7 @@ pub noinline fn shutdown(self: *ThreadPool) void { // Wake up any threads sleeping on the idle_event. // TODO: I/O polling notification here. if (sync.idle > 0) self.idle_event.shutdown(); + if (sync.spawned == 0) self.join_event.notify(); return; }); } @@ -335,11 +336,8 @@ 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 - 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)); - } + self.join_event.wait(); + const sync: Sync = @bitCast(self.sync.load(.monotonic)); assert(sync.state == .shutdown); assert(sync.spawned == 0);