Skip to content

Instantly share code, notes, and snippets.

@TwP
Created May 7, 2009 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TwP/108117 to your computer and use it in GitHub Desktop.
Save TwP/108117 to your computer and use it in GitHub Desktop.
class ReentrantMutex < Mutex
def initialize
super
@locker = nil
end
alias :original_synchronize :synchronize
def synchronize
if @locker == Thread.current
yield
else
original_synchronize {
begin
@locker = Thread.current
yield
ensure
@locker = nil
end
}
end
end
end # class ReentrantMutex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment