Ruby 2.4

Monitor

class Monitor

Parent:ObjectIncluded modules:MonitorMixin

如果要为互斥模块设置锁定对象,请使用Monitor类。

require 'monitor' lock = Monitor.new lock.synchronize do # exclusive access end