Skip to content
Merged
Changes from 3 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
10 changes: 8 additions & 2 deletions src/bls/ThreadPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ pub fn init(allocator_: Allocator, io: std.Io, opts: Opts) (Allocator.Error || s
std.debug.assert(opts.n_workers <= MAX_WORKERS);

const pool = try allocator_.create(ThreadPool);
errdefer pool.deinit(io);

pool.* = .{
.allocator = allocator_,
.n_workers = opts.n_workers,
.n_workers = 0,
.queue = .{},
};
for (0..pool.n_workers) |i| {

for (0..opts.n_workers) |i| {
pool.threads[i] = try std.Thread.spawn(.{}, workerLoop, .{ pool, io });
pool.n_workers += 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come this one-at-a-time is needed?
If there is an error part-way through, the pool will be destroyed? (Or does it need a allocator_.destroy(pool)?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, any error will deinit the pool right now

}
std.debug.assert(pool.n_workers == opts.n_workers);

return pool;
}

Expand Down
Loading