fixed merge conflict

This commit is contained in:
Chris Boesch
2026-04-14 22:23:33 +02:00
2 changed files with 12 additions and 6 deletions

View File

@@ -45,8 +45,9 @@ const Io = std.Io;
const print = std.debug.print; const print = std.debug.print;
const SearchResult = struct { const SearchResult = struct {
worker_id: u8, found: bool,
index: usize, worker_id: u8 = 0,
index: usize = 0,
}; };
pub fn main(init: std.process.Init) !void { pub fn main(init: std.process.Init) !void {
@@ -71,6 +72,7 @@ pub fn main(init: std.process.Init) !void {
// Wait for the first result. // Wait for the first result.
const result = try queue.getOne(io); const result = try queue.getOne(io);
if (result.found)
print("Worker {} found signal start over threshold at index {}!\n", .{ result.worker_id, result.index }); print("Worker {} found signal start over threshold at index {}!\n", .{ result.worker_id, result.index });
} }
@@ -94,10 +96,14 @@ fn searchThreshold(
if (val >= threshold) { if (val >= threshold) {
queue.putOne(io, .{ queue.putOne(io, .{
.found = true,
.worker_id = worker_id, .worker_id = worker_id,
.index = base_offset + i, .index = base_offset + i,
}) catch return; }) catch return;
return; return;
} }
} }
// Nothing found
queue.putOneUncancelable(io, .{ .found = false }) catch return;
} }

View File

@@ -1,6 +1,6 @@
--- exercises/093_async9.zig 2026-04-14 08:32:33.014583120 -0700 --- exercises/093_async9.zig 2026-04-14 22:20:23.519107582 +0200
+++ answers/093_async9.zig 2026-04-14 08:32:24.459647047 -0700 +++ answers/093_async9.zig 2026-04-14 22:06:30.606912044 +0200
@@ -62,10 +62,10 @@ @@ -63,10 +63,10 @@
// Launch two workers, each searching half the array. // Launch two workers, each searching half the array.
// Remember, we want them to be guaranteed separate units of concurrency. // Remember, we want them to be guaranteed separate units of concurrency.