mirror of
https://codeberg.org/ziglings/exercises.git
synced 2025-12-27 16:05:37 +00:00
forgotten thread-sleep fix added
This commit is contained in:
parent
189376944c
commit
11d8172136
|
|
@ -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.Thread.sleep(1500 * std.time.ns_per_ms);
|
||||
std.posix.nanosleep(4, 0);
|
||||
std.debug.print("Some weird stuff, after starting the threads.\n", .{});
|
||||
}
|
||||
// After we have left the closed area, we wait until
|
||||
|
|
@ -117,12 +117,12 @@ 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.Thread.sleep(200 * num * std.time.ns_per_ms);
|
||||
std.posix.nanosleep(1 * num, 0);
|
||||
std.debug.print("thread {d}: {s}\n", .{ num, "started." });
|
||||
|
||||
// This timer simulates the work of the thread.
|
||||
const work_time = 3 * ((5 - num % 3) - 2);
|
||||
std.Thread.sleep(work_time * std.time.ns_per_s);
|
||||
std.posix.nanosleep(work_time, 0);
|
||||
|
||||
std.debug.print("thread {d}: {s}\n", .{ num, "finished." });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
--- exercises/104_threading.zig 2024-04-10 19:12:29.878856370 +0200
|
||||
+++ answers/104_threading.zig 2024-04-10 19:11:22.304265713 +0200
|
||||
--- exercises/104_threading.zig 2025-11-15 19:13:35.359496111 +0100
|
||||
+++ answers/104_threading.zig 2025-11-15 19:11:20.468752429 +0100
|
||||
@@ -97,12 +97,12 @@
|
||||
defer handle.join();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user