diff options
| author | MatthijsBlom <matthijsblom@noreply.codeberg.org> | 2026-04-18 23:46:59 +0200 |
|---|---|---|
| committer | MatthijsBlom <matthijsblom@noreply.codeberg.org> | 2026-04-18 23:46:59 +0200 |
| commit | e0470c4f45694fde5b884cb43d2712cef8c7d2eb (patch) | |
| tree | 018a656b5a2e58b135a8ec11b13e5c597e06c430 /exercises/091_async7.zig | |
| parent | f35c9419d2d2087e9703256a030b382ef17c6c21 (diff) | |
demonstrate the benefit of the mutex
Diffstat (limited to 'exercises/091_async7.zig')
| -rw-r--r-- | exercises/091_async7.zig | 6 |
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; } } |
