Skip to content

Commit

Permalink
tweak demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 11, 2025
1 parent a446661 commit 0366d1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion book-src/07-02-shared-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ When we want to mutate data shared between threads, [`Mutex`](**Mut**ually **ex*
```zig
{{#include ../src/07-02.zig}}
```
If we remove Mutex protection, the result will most like be less than 300.
If we remove Mutex protection, the result will most like be less than 30,000.

[`Mutex`]: https://ziglang.org/documentation/0.11.0/std/#A;std:Thread.Mutex
4 changes: 2 additions & 2 deletions src/07-02.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SharedData = struct {
self.mutex.lock();
defer self.mutex.unlock();

for (0..100) |_| {
for (0..10000) |_| {
self.value += increment;
}
}
Expand All @@ -26,5 +26,5 @@ pub fn main() !void {
const t2 = try Thread.spawn(.{}, SharedData.updateValue, .{ &shared_data, 2 });
defer t2.join();
}
try std.testing.expectEqual(shared_data.value, 300);
try std.testing.expectEqual(shared_data.value, 30_000);
}

0 comments on commit 0366d1b

Please sign in to comment.