Mutex: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 3:
[[Category:Encyclopedia]]
A '''mutex''' (
A mutex is said to be seized by a [[task]] decreasing ''k''.
It is released when the task restores ''k''. Mutexes are typically used to protect a shared resource from concurrent access.
Line 1,232:
$lock.protect: { your-ad-here() }</syntaxhighlight>
Locks are reentrant. You may explicitly lock and unlock them, but the syntax above guarantees the lock will be unlocked on scope exit, even if by thrown exception or other exotic control flow. That being said, direct use of locks is discouraged in
=={{header|Ruby}}==
Line 1,395:
However, to avoid excessive latency, a VM whose thread were continuing would need to signal to the host that it no longer needed the resource so the lock could be released thereby making it available to the other VM(s). Typically, a shared resource might need to be represented something like this in a Wren script:
<syntaxhighlight lang="
// obtain a pointer to the resource when available
construct new() {}
|