From ba2a9622c46b2410a90831b7b71dd2c2ffefb439 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Wed, 10 Apr 2024 19:13:46 +0200 Subject: Additional timer in thread start added --- exercises/104_threading.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'exercises') diff --git a/exercises/104_threading.zig b/exercises/104_threading.zig index 7865839..ac40b3c 100644 --- a/exercises/104_threading.zig +++ b/exercises/104_threading.zig @@ -106,7 +106,7 @@ pub fn main() !void { // After the threads have been started, // they run in parallel and we can still do some work in between. - std.time.sleep((1) * std.time.ns_per_s); + std.time.sleep(1500 * std.time.ns_per_ms); std.debug.print("Some weird stuff, after starting the threads.\n", .{}); } // After we have left the closed area, we wait until @@ -117,10 +117,11 @@ pub fn main() !void { // This function is started with every thread that we set up. // In our example, we pass the number of the thread as a parameter. fn thread_function(num: usize) !void { + std.time.sleep(200 * num * std.time.ns_per_ms); std.debug.print("thread {d}: {s}\n", .{ num, "started." }); // This timer simulates the work of the thread. - const work_time = 2 * ((5 - num % 3) - 2); + const work_time = 3 * ((5 - num % 3) - 2); std.time.sleep(work_time * std.time.ns_per_s); std.debug.print("thread {d}: {s}\n", .{ num, "finished." }); -- cgit v1.2.3