Skip to content
On this page

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class · Ruby 3.4

Thread::Mutex

< Object 7 instance methods 1 class methods

Thread::Mutex implements a simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.

Example:

Example
semaphore = Thread::Mutex.new

a = Thread.new {
  semaphore.synchronize {
    # access shared resource
  }
}

b = Thread.new {
  semaphore.synchronize {
    # access shared resource
  }
}

Class methods 1

Instance methods 7