From 6a6da59a79a59e93aa75766739e4a7d7a717d54b Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 27 Nov 2023 11:43:02 +0500 Subject: [PATCH] basic threading handler boiler --- src/main.zig | 6 ++++-- src/threads.zig | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/threads.zig diff --git a/src/main.zig b/src/main.zig index 6a72c9b..c38ca4d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,7 @@ const std = @import("std"); const util = @import("util.zig"); +const threads = @import("threads.zig"); const InitError = error { NotEnoughArgs, @@ -58,6 +59,7 @@ pub fn main() !void { var buffs = try util.Buffers.init(std.heap.page_allocator, opts.width, opts.height, 1000); defer buffs.deinit(); - - std.debug.print("{any}\n", .{opts}); + + var thread_manager = try threads.ThreadManager.init(std.heap.page_allocator, opts.n_quant_jobs); + defer thread_manager.deinit(); } diff --git a/src/threads.zig b/src/threads.zig new file mode 100644 index 0000000..752c5e4 --- /dev/null +++ b/src/threads.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub const ThreadManager = struct { + threads: std.ArrayList(std.Thread), + arena: std.heap.ArenaAllocator, + + const Self = @This(); + + pub fn init(alloc: std.mem.Allocator, n_quant_jobs: usize) !Self { + _ = n_quant_jobs; + var arena = std.heap.ArenaAllocator.init(alloc); + var thread_mgr = Self { + .threads = std.ArrayList(std.Thread).init(arena.allocator()), + .arena = arena, + }; + return thread_mgr; + } + + pub fn deinit(self: *Self) void { + self.threads.deinit(); + self.arena.deinit(); + } +};