class RecursiveMutex
A recursive mutex lets you lock in various threads recursively, allowing you to do multiple locks one inside another.
You really shouldn’t use this, but in some cases it makes your life easier.
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/thread/recursive_mutex.rb, line 18 def initialize @threads_lock = Mutex.new @threads = Hash.new { |h, k| h[k] = 0 } super end
Public Instance Methods
lock()
click to toggle source
Lock the mutex.
Calls superclass method
# File lib/thread/recursive_mutex.rb, line 26 def lock super if @threads_lock.synchronize{ (@threads[Thread.current] += 1) == 1 } end
unlock()
click to toggle source
Unlock the mutex.
Calls superclass method
# File lib/thread/recursive_mutex.rb, line 31 def unlock if @threads_lock.synchronize{ (@threads[Thread.current] -= 1) == 0 } @threads.delete(Thread.current) super end end