Name
Mutex — Mutual exclusion class
Synopsis
This class represents mutually exclusive locks.
Required Library
require ‘thread’
Class Method
Mutex::new
Creates a
Mutex
object
Instance Methods
m
.lock
Locks the
Mutex
objectm
.m
.locked?
Returns
true
ifm
is locked.m
.synchronize {...}
Locks
m
and runs the block, then releases the lock when the block exits.m
.try_lock
Attempts to lock
m
. Returnsfalse
if lock fails.m
.unlock
Releases lock on
m
.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.