diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-01-02 16:29:21 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-01-02 16:29:21 -0500 |
| commit | 1a4a7250bb25a843dc977d0c6cdf65ce0df0e6c5 (patch) | |
| tree | 05a1da5e11951f13d1f9f3d36d512829319cf9f0 /docs/mutexed.md | |
| parent | be384c0caa92cb152c264125fb265373e6a50440 (diff) | |
Add some light docs for mutexed access
Diffstat (limited to 'docs/mutexed.md')
| -rw-r--r-- | docs/mutexed.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/mutexed.md b/docs/mutexed.md new file mode 100644 index 00000000..eebf9015 --- /dev/null +++ b/docs/mutexed.md @@ -0,0 +1,24 @@ +# Mutexed Data + +To serve the general case of synchronizing access to shared datastructures, +Tomo uses the `mutexed` keyword, which returns a function which can be used +to ensure that all access to a datastructure is guarded by a mutex: + +```tomo +with_nums := mutexed [10, 20, 30] + +thread := Thread.new(func(): + with_nums(func(nums:&[Int]): + nums:insert(30) + ) +) + +with_nums(func(nums:&[Int]): + nums:insert(40) +) + +thread:join() +``` + +Without having a mutex guard, the code above could run into concurrency issues +leading to data corruption. |
