require 'thread'class Object def synchronize mutex.synchronize { yield self } end def mutex @mutex ||= Mutex.new endend