Class | Mutex |
In: |
lib/thread.rb
|
Parent: | Object |
Mutex implements a simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.
Example:
require 'thread' semaphore = Mutex.new a = Thread.new { semaphore.synchronize { # access shared resource } } b = Thread.new { semaphore.synchronize { # access shared resource } }
If the mutex is locked, unlocks the mutex, wakes one waiting thread, and yields in a critical section.
Obtains a lock, runs the block, and releases the lock when the block completes. See the example under Mutex.