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.
Acquires the exclusive lock.
Acquires the exclusive lock for the duration of the block.
Releases the exclusive lock.
Reference
Reference
Reference
Object
Object
Object
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.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Sync/Mutex.html