class Thread::Monitor

Use the Monitor class when you want to have a lock object for blocks with mutual exclusion.

lock = Monitor.new
lock.synchronize do
  # exclusive access
end

Contrary to Mutex, Monitor is reentrant:

lock = Monitor.new
lock.synchronize do
  lock.synchronize do
    # exclusive access
  end
end