From bfb464bc3020c782071666927c4bcb02d940e8e4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 4 Nov 2024 13:30:10 -0800 Subject: [PATCH] Revert "Fix potential ThreadPool UAF (#113)" This reverts commit dbe22910a43e9e8ec9948d3cbd73d8488a074967, reversing changes made to 43c7e4b3308f359e5b758db2d824d7c447f4ed3f. --- src/ThreadPool.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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);