Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove race from threadpool #130

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/ThreadPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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);
Expand Down
Loading