1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/prelude.rb

26 lines
293 B
Ruby
Raw Normal View History

# Mutex
class Mutex
def synchronize
self.lock
begin
yield
ensure
self.unlock rescue nil
end
end
end
# Thread
class Thread
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
def self.exclusive
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
yield
}
end
end