1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Mutex class Mutex def synchronize self.lock begin yield ensure self.unlock end end end # Thread class Thread MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new def self.exclusive MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{ yield } end end