Skip to content

Commit

Permalink
fix thread_pool.warm returning without spawning new threads
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Feb 5, 2025
1 parent d7f5ea4 commit cacb272
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/thread_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,17 @@ pub fn warm(self: *ThreadPool, count: u14) void {
while (sync.spawned < to_spawn) {
var new_sync = sync;
new_sync.spawned += 1;
sync = @as(Sync, @bitCast(self.sync.cmpxchgWeak(
sync = @bitCast(self.sync.cmpxchgWeak(
@as(u32, @bitCast(sync)),
@as(u32, @bitCast(new_sync)),
.release,
.monotonic,
) orelse break));
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_thread_stack_size };
const thread = std.Thread.spawn(spawn_config, Thread.run, .{self}) catch return self.unregister(null);
thread.detach();
) orelse blk: {
const spawn_config = std.Thread.SpawnConfig{ .stack_size = self.stack_size };
const thread = std.Thread.spawn(spawn_config, Thread.run, .{self}) catch return self.unregister(null);
thread.detach();
break :blk @as(u32, @bitCast(new_sync));
});
}
}

Expand Down

0 comments on commit cacb272

Please sign in to comment.