Skip to content

Commit

Permalink
use configured stack size for threads in thread_pool
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Jan 23, 2025
1 parent 1a5e772 commit a07bb13
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/thread_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,34 @@ pub fn warm(self: *ThreadPool, count: u14) void {

const to_spawn = @min(count - sync.spawned, @as(u14, @truncate(self.max_threads)));
while (sync.spawned < to_spawn) {
<<<<<<< HEAD
=======
<<<<<<< Updated upstream
while (true) {
var new_sync = sync;
new_sync.spawned += 1;
const old_sync = self.sync.cmpxchgWeak(
@as(u32, @bitCast(sync)),
@as(u32, @bitCast(new_sync)),
.release,
.monotonic,
);
if (old_sync == null) {
sync = new_sync;
break;
} else {
sync = @as(Sync, @bitCast(old_sync.?));
if (sync.spawned >= to_spawn) {
return;
}
}
}

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();
=======
>>>>>>> 9b0e55670 (use configured stack size for threads in thread_pool)
var new_sync = sync;
new_sync.spawned += 1;
sync = @bitCast(self.sync.cmpxchgWeak(
Expand Down Expand Up @@ -472,7 +500,7 @@ noinline fn notifySlow(self: *ThreadPool, is_waking: bool) void {

// We signaled to spawn a new thread
if (can_wake and sync.spawned < self.max_threads) {
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_thread_stack_size };
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);
// if (self.name.len > 0) thread.setName(self.name) catch {};
return thread.detach();
Expand Down

0 comments on commit a07bb13

Please sign in to comment.