mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-07-28 18:25:16 +00:00
Merge pull request 'Fix misleading comments' (#476) from it3x/fix-threads-comment into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/476
This commit is contained in:
@@ -75,10 +75,10 @@ pub fn main() !void {
|
|||||||
std.debug.print("Starting work...\n", .{});
|
std.debug.print("Starting work...\n", .{});
|
||||||
|
|
||||||
// These curly braces are very important, they are necessary
|
// These curly braces are very important, they are necessary
|
||||||
// to enclose the area where the threads are called.
|
// to enclose the area where the threads are called and joined.
|
||||||
// Without these braces, the program would not wait for the
|
// With these braces, the program will block and wait for all threads
|
||||||
// end of the threads and they would continue to run beyond the
|
// to finish right at the closing brace of this block, ensuring
|
||||||
// end of the program.
|
// "Zig is cool!" is always printed last.
|
||||||
{
|
{
|
||||||
// Now we start the first thread, with the number as parameter
|
// Now we start the first thread, with the number as parameter
|
||||||
const handle = try std.Thread.spawn(.{}, thread_function, .{1});
|
const handle = try std.Thread.spawn(.{}, thread_function, .{1});
|
||||||
@@ -102,8 +102,7 @@ pub fn main() !void {
|
|||||||
try io.sleep(std.Io.Duration.fromMilliseconds(400), .awake);
|
try io.sleep(std.Io.Duration.fromMilliseconds(400), .awake);
|
||||||
std.debug.print("Some weird stuff, after starting the threads.\n", .{});
|
std.debug.print("Some weird stuff, after starting the threads.\n", .{});
|
||||||
}
|
}
|
||||||
// After we have left the closed area, we wait until
|
// The threads are guaranteed to be finished by the time we reach here.
|
||||||
// the threads have run through, if this has not yet been the case.
|
|
||||||
std.debug.print("Zig is cool!\n", .{});
|
std.debug.print("Zig is cool!\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user