summaryrefslogtreecommitdiff
path: root/exercises/091_async7.zig
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2026-04-19 14:21:24 +0200
committerChris Boesch <chrboesch@noreply.codeberg.org>2026-04-19 14:21:24 +0200
commitca8aee84ad920f9af173e0eebf7310ebde217fef (patch)
tree4396fca265e59ca073508e89327deb7d2935d172 /exercises/091_async7.zig
parentf35c9419d2d2087e9703256a030b382ef17c6c21 (diff)
parentc4cb76ea8e1ac9b061f1436aafcd0bef55183e0f (diff)
Merge pull request 'Demonstrate the benefit of a mutex' (#408) from MatthijsBlom/ziglings:matthijsblom-patch-1 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/408
Diffstat (limited to 'exercises/091_async7.zig')
-rw-r--r--exercises/091_async7.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/exercises/091_async7.zig b/exercises/091_async7.zig
index 1b83795..629d276 100644
--- a/exercises/091_async7.zig
+++ b/exercises/091_async7.zig
@@ -52,6 +52,12 @@ fn increment(io: std.Io, state: *SharedState, times: u32) void {
state.mutex.??? catch return;
defer state.mutex.unlock(); // <-- what's missing here?
+ // Sleep to give the other tasks a chance to run in the meantime.
+ // We do this here only to make nondeterminism more visible.
+ io.sleep(std.Io.Duration.fromMilliseconds(1), .awake) catch {};
+
+ // What happens if you neglect to lock the mutex?
+
state.counter += 1;
}
}