模块 Mutex_m
mutex_m.rb¶ ↑
当需要 ‘mutex_m’ 时,任何扩展或包含 Mutex_m
的对象都将被视为互斥锁 (Mutex)。
首先需要引入标准库 Mutex_m
require "mutex_m"
从这里你可以使用 Mutex 实例方法扩展一个对象
obj = Object.new obj.extend Mutex_m
或者将 Mutex_m
混入你的模块,以便你的类继承 Mutex 实例方法 —— 记住在你的类的 initialize 方法中调用 super()。
class Foo include Mutex_m def initialize # ... super() end # ... end obj = Foo.new # this obj can be handled like Mutex
常量
- VERSION
公共实例方法
mu_lock() 点击切换源代码
参见 Thread::Mutex#lock
# File mutex_m-0.3.0/lib/mutex_m.rb, line 96 def mu_lock @_mutex.lock end
mu_locked?() 点击切换源代码
参见 Thread::Mutex#locked?
# File mutex_m-0.3.0/lib/mutex_m.rb, line 86 def mu_locked? @_mutex.locked? end
mu_synchronize(&block) 点击切换源代码
参见 Thread::Mutex#synchronize
# File mutex_m-0.3.0/lib/mutex_m.rb, line 81 def mu_synchronize(&block) @_mutex.synchronize(&block) end
mu_try_lock() 点击切换源代码
参见 Thread::Mutex#try_lock
# File mutex_m-0.3.0/lib/mutex_m.rb, line 91 def mu_try_lock @_mutex.try_lock end
mu_unlock() 点击切换源代码
参见 Thread::Mutex#unlock
# File mutex_m-0.3.0/lib/mutex_m.rb, line 101 def mu_unlock @_mutex.unlock end
sleep(timeout = nil) 点击切换源代码
参见 Thread::Mutex#sleep
# File mutex_m-0.3.0/lib/mutex_m.rb, line 106 def sleep(timeout = nil) @_mutex.sleep(timeout) end