Ruby 2.4

Mutex_m

module Mutex_m

mutex_m.rb

当需要'mutex_m'时,任何扩展或包含Mutex_m的对象都将被视为Mutex。

首先要求标准库Mutex_m:

require "mutex_m.rb"

从这里你可以用Mutex实例方法扩展一个对象:

obj = Object.new obj.extend Mutex_m

或者将Mutex_m混入您的模块中,以继承Mutex实例方法。

class Foo include Mutex_m # ... end obj = Foo.new # this obj can be handled like Mutex

公共实例方法

mu_lock() Show source

See Mutex#lock

# File lib/mutex_m.rb, line 87 def mu_lock @_mutex.lock end

mu_locked?() Show source

See Mutex#locked?

# File lib/mutex_m.rb, line 77 def mu_locked? @_mutex.locked? end

mu_synchronize(&block) Show source

See Mutex#synchronize

# File lib/mutex_m.rb, line 72 def mu_synchronize(&block) @_mutex.synchronize(&block) end

mu_try_lock() Show source

See Mutex#try_lock

# File lib/mutex_m.rb, line 82 def mu_try_lock @_mutex.try_lock end

mu_unlock() Show source

See Mutex#unlock

# File lib/mutex_m.rb, line 92 def mu_unlock @_mutex.unlock end

sleep(timeout = nil) Show source

See Mutex#sleep

# File lib/mutex_m.rb, line 97 def sleep(timeout = nil) @_mutex.sleep(timeout) end