threads/mutex_subclass.rb
tests/_examples/threads/mutex_subclass.rb in the metorex repository.
class Guard < Mutex; end
guard = Guard.new
guard.lock
p [guard.locked?, guard.owned?]
begin
guard.synchronize {}
rescue ThreadError => error
p error.message
end
guard.unlock
p guard.synchronize { :inside }
Output:
[true, true]
"deadlock; recursive locking"
:inside