On this page
End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class · Ruby 3.0
Mutex
Mutex implements a simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.
Example:
Example
semaphore = Mutex.new a = Thread.new { semaphore.synchronize { # access shared resource } } b = Thread.new { semaphore.synchronize { # access shared resource } }
Class methods 1
Instance methods 7
Ruby version changes 1
-
3.0
-
Mutexis now acquired per-Fiberinstead of per-Thread. This change should be compatible for essentially all usages and avoids blocking when using a scheduler. [Feature #16792]
-