模块 Mutex_m

mutex_m.rb

当 'mutex_m' 被 require 时,任何扩展或包含 Mutex_m 的对象将被视为互斥锁。

首先需要标准库 Mutex_m

require "mutex_m.rb"

从这里你可以用互斥锁实例方法扩展一个对象

obj = Object.new
obj.extend Mutex_m

或者将 Mutex_m 混合到你的模块中,使你的类继承互斥锁实例方法 - 记住在你的类初始化方法中调用 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 lib/mutex_m.rb, line 91
def mu_lock
  @_mutex.lock
end
mu_locked?() 点击切换源代码

参见 Thread::Mutex#locked?

# File lib/mutex_m.rb, line 81
def mu_locked?
  @_mutex.locked?
end
mu_synchronize(&block) 点击切换源代码

参见 Thread::Mutex#synchronize

# File lib/mutex_m.rb, line 76
def mu_synchronize(&block)
  @_mutex.synchronize(&block)
end
mu_try_lock() 点击切换源代码

参见 Thread::Mutex#try_lock

# File lib/mutex_m.rb, line 86
def mu_try_lock
  @_mutex.try_lock
end
mu_unlock() 点击切换源代码

参见 Thread::Mutex#unlock

# File lib/mutex_m.rb, line 96
def mu_unlock
  @_mutex.unlock
end
sleep(timeout = nil) 点击切换源代码

参见 Thread::Mutex#sleep

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