class
Sync::Mutex
- Sync::Mutex
- Reference
- Object
Overview
A mutual exclusion lock to protect critical sections.
A single fiber can acquire the lock at a time. No other fiber can acquire the lock while a fiber holds it.
This lock can for example be used to protect the access to some resources, with the guarantee that only one section of code can ever read, write or mutate said resources.
NOTE Consider Exclusive(T)
to protect a value T
with a Mutex
.
Included Modules
Defined in:
mutex.crConstructors
Instance Method Summary
-
#lock : Nil
Acquires the exclusive lock.
-
#synchronize(& : -> U) : U forall U
Acquires the exclusive lock for the duration of the block.
-
#unlock : Nil
Releases the exclusive lock.
Constructor Detail
Instance Method Detail
def synchronize(& : -> U) : U forall U
#
Acquires the exclusive lock for the duration of the block. The lock will be released automatically before returning, or if the block raises an exception.