mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
6871c34274
[ruby-dev:32935] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
25 lines
293 B
Ruby
25 lines
293 B
Ruby
|
|
# 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
|
|
|