summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2026-04-14 17:56:35 +0200
committerChris Boesch <chrboesch@noreply.codeberg.org>2026-04-14 17:56:35 +0200
commit3f11ad125367b0ed2fd21c776cef061695174898 (patch)
tree9e9d4de260dbd72ac90a5d4d7dd31d39324d63f4
parenta4efd69e1108afcdfa7916f2d5cdff7ecb41128d (diff)
parent2afd0f9709bc9bf42d2cfdfa175221516525e36c (diff)
Merge pull request '093_async9: small fixes' (#400) from tjk/ziglings-exercises:93-async9 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/400
-rw-r--r--exercises/093_async9.zig10
-rw-r--r--patches/patches/093_async9.patch17
2 files changed, 11 insertions, 16 deletions
diff --git a/exercises/093_async9.zig b/exercises/093_async9.zig
index 9d95092..741462d 100644
--- a/exercises/093_async9.zig
+++ b/exercises/093_async9.zig
@@ -33,7 +33,7 @@
// Let's try a slightly simplified example from signal processing:
// Suppose we're looking for the beginning of a signal above the noise
// level. To do this, we compare each entry from beginning to end with
-// the threshold.To speed things up a bit, we split the signal into
+// the threshold. To speed things up a bit, we split the signal into
// two halves and have two parallel workers search for them.
// Who finds the beginning first "wins" and thus ends the other one.
//
@@ -61,10 +61,11 @@ pub fn main(init: std.process.Init) !void {
var queue = Io.Queue(SearchResult).init(&buf);
// Launch two workers, each searching half the array.
- var f1 = ???(searchRange, .{ data[0..mid], target, 0, 0, &queue, io });
+ // Remember, we want them to be guaranteed separate units of concurrency.
+ var f1 = ???(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue });
defer _ = f1.cancel(io);
- var f2 = ???(searchRange, .{ data[mid..], target, mid, 1, &queue, io });
+ var f2 = ???(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue });
defer _ = f2.cancel(io);
// Wait for the first result.
@@ -87,7 +88,7 @@ fn searchThreshold(
// all workers would continue until the end.
io.sleep(Io.Duration.fromMilliseconds(1), .awake) catch return;
- // To test this, you can view the work of the workers
+ // To test this, you can uncomment this to view the work of the workers
// and then comment out the pause.
// print("id: {} - val: {}\n", .{ worker_id, val });
@@ -100,4 +101,3 @@ fn searchThreshold(
}
}
}
-
diff --git a/patches/patches/093_async9.patch b/patches/patches/093_async9.patch
index ef18d3f..c8cc714 100644
--- a/patches/patches/093_async9.patch
+++ b/patches/patches/093_async9.patch
@@ -1,20 +1,15 @@
---- exercises/093_async9.zig 2026-04-14 09:50:05.694073287 +0200
-+++ answers/093_async9.zig 2026-04-14 09:49:58.604934765 +0200
-@@ -61,10 +61,10 @@
- var queue = Io.Queue(SearchResult).init(&buf);
+--- exercises/093_async9.zig 2026-04-14 08:32:33.014583120 -0700
++++ answers/093_async9.zig 2026-04-14 08:32:24.459647047 -0700
+@@ -62,10 +62,10 @@
// Launch two workers, each searching half the array.
-- var f1 = ???(searchRange, .{ data[0..mid], target, 0, 0, &queue, io });
+ // Remember, we want them to be guaranteed separate units of concurrency.
+- var f1 = ???(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue });
+ var f1 = try io.concurrent(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue });
defer _ = f1.cancel(io);
-- var f2 = ???(searchRange, .{ data[mid..], target, mid, 1, &queue, io });
+- var f2 = ???(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue });
+ var f2 = try io.concurrent(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue });
defer _ = f2.cancel(io);
// Wait for the first result.
-@@ -100,4 +100,3 @@
- }
- }
- }
--