aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2024-04-10 14:18:01 +0000
committerChris Boesch <chrboesch@noreply.codeberg.org>2024-04-10 14:18:01 +0000
commit2122c477a04f54655f71f78217d845485254cfab (patch)
treea19fcd97871c17aaea548621f9dc7d4b10eecbe5
parent564916db81e4f748f430528c5366673504221c1b (diff)
parent7732cd7716236dcdf42b205d7983af6b12bba68b (diff)
Merge pull request 'Greater gradation of timers built into the threads' (#76) from I75 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/76
-rw-r--r--exercises/104_threading.zig6
-rw-r--r--patches/patches/104_threading.patch4
2 files changed, 7 insertions, 3 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.
diff --git a/patches/patches/104_threading.patch b/patches/patches/104_threading.patch
index 58410a8..304d39f 100644
--- a/patches/patches/104_threading.patch
+++ b/patches/patches/104_threading.patch
@@ -1,5 +1,5 @@
---- exercises/104_threading.zig 2024-03-05 09:09:04.013974229 +0100
-+++ answers/104_threading.zig 2024-03-05 09:12:03.987162883 +0100
+--- exercises/104_threading.zig 2024-04-10 16:02:33.680771772 +0200
++++ answers/104_threading.zig 2024-04-10 16:01:00.042331517 +0200
@@ -97,12 +97,12 @@
defer handle.join();