diff options
| author | Chris Boesch <[email protected]> | 2024-04-10 16:06:23 +0200 |
|---|---|---|
| committer | Chris Boesch <[email protected]> | 2024-04-10 16:06:23 +0200 |
| commit | 7732cd7716236dcdf42b205d7983af6b12bba68b (patch) | |
| tree | c6ac41217af423972b96a3258d79b5e350fe0412 /exercises | |
| parent | c0ff1b70c152603bc5680abfb1793b176125d7c8 (diff) | |
| download | ziglings-7732cd7716236dcdf42b205d7983af6b12bba68b.tar.xz ziglings-7732cd7716236dcdf42b205d7983af6b12bba68b.zip | |
Greater gradation of timers built into the threads
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/104_threading.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/exercises/104_threading.zig b/exercises/104_threading.zig index 8aeb683..7865839 100644 --- a/exercises/104_threading.zig +++ b/exercises/104_threading.zig @@ -118,7 +118,11 @@ pub fn main() !void { // In our example, we pass the number of the thread as a parameter. fn thread_function(num: usize) !void { std.debug.print("thread {d}: {s}\n", .{ num, "started." }); - std.time.sleep((5 - num % 3) * std.time.ns_per_s); + + // This timer simulates the work of the thread. + const work_time = 2 * ((5 - num % 3) - 2); + std.time.sleep(work_time * std.time.ns_per_s); + std.debug.print("thread {d}: {s}\n", .{ num, "finished." }); } // This is the easiest way to run threads in parallel. |
