my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

093_async9: small fixes

Tom (Apr 14, 2026, 8:32 AM -0700) 2afd0f97 a4efd69e

+11 -16
+5 -5
exercises/093_async9.zig
··· 33 33 // Let's try a slightly simplified example from signal processing: 34 34 // Suppose we're looking for the beginning of a signal above the noise 35 35 // level. To do this, we compare each entry from beginning to end with 36 - // the threshold.To speed things up a bit, we split the signal into 36 + // the threshold. To speed things up a bit, we split the signal into 37 37 // two halves and have two parallel workers search for them. 38 38 // Who finds the beginning first "wins" and thus ends the other one. 39 39 // ··· 61 61 var queue = Io.Queue(SearchResult).init(&buf); 62 62 63 63 // Launch two workers, each searching half the array. 64 - var f1 = ???(searchRange, .{ data[0..mid], target, 0, 0, &queue, io }); 64 + // Remember, we want them to be guaranteed separate units of concurrency. 65 + var f1 = ???(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue }); 65 66 defer _ = f1.cancel(io); 66 67 67 - var f2 = ???(searchRange, .{ data[mid..], target, mid, 1, &queue, io }); 68 + var f2 = ???(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue }); 68 69 defer _ = f2.cancel(io); 69 70 70 71 // Wait for the first result. ··· 87 88 // all workers would continue until the end. 88 89 io.sleep(Io.Duration.fromMilliseconds(1), .awake) catch return; 89 90 90 - // To test this, you can view the work of the workers 91 + // To test this, you can uncomment this to view the work of the workers 91 92 // and then comment out the pause. 92 93 // print("id: {} - val: {}\n", .{ worker_id, val }); 93 94 ··· 100 101 } 101 102 } 102 103 } 103 -
+6 -11
patches/patches/093_async9.patch
··· 1 - --- exercises/093_async9.zig 2026-04-14 09:50:05.694073287 +0200 2 - +++ answers/093_async9.zig 2026-04-14 09:49:58.604934765 +0200 3 - @@ -61,10 +61,10 @@ 4 - var queue = Io.Queue(SearchResult).init(&buf); 1 + --- exercises/093_async9.zig 2026-04-14 08:32:33.014583120 -0700 2 + +++ answers/093_async9.zig 2026-04-14 08:32:24.459647047 -0700 3 + @@ -62,10 +62,10 @@ 5 4 6 5 // Launch two workers, each searching half the array. 7 - - var f1 = ???(searchRange, .{ data[0..mid], target, 0, 0, &queue, io }); 6 + // Remember, we want them to be guaranteed separate units of concurrency. 7 + - var f1 = ???(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue }); 8 8 + var f1 = try io.concurrent(searchThreshold, .{ io, data[0..mid], threshold, 0, 0, &queue }); 9 9 defer _ = f1.cancel(io); 10 10 11 - - var f2 = ???(searchRange, .{ data[mid..], target, mid, 1, &queue, io }); 11 + - var f2 = ???(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue }); 12 12 + var f2 = try io.concurrent(searchThreshold, .{ io, data[mid..], threshold, mid, 1, &queue }); 13 13 defer _ = f2.cancel(io); 14 14 15 15 // Wait for the first result. 16 - @@ -100,4 +100,3 @@ 17 - } 18 - } 19 - } 20 - -