Lightweight thread pool with back-pressure and zero allocations after initialization.
The standard library's std.Thread.Pool
is designed for large jobs. As such, each scheduled job has non-trivial overhead.
var tp = try zul.ThreadPool(someTask).init(allocator, .{.count = 4, .backlog = 500});
defer tp.deinit(allocator);
tp.spawn(.{1, true});
fn someTask(i: i32, allow: bool) void {
}
zul.ThreadPool(comptime Fn: type)
is a simple and memory efficient way to have pre-initialized threads ready to process incoming work. The ThreadPool is a generic and takes the function to execute as a parameter.
init(...) !*Self
fn init(
allocator: std.mem.Allocator,
opts: .{
.count: u32 = 1,
.backlog: u32 = 500,
}
) !*ThreadPool(Fn)
Creates a zul.ThreadPool(Fn)
.