class MonitorMixin::ConditionVariable

FIXME: This isn’t documented in Nutshell.

Since MonitorMixin.new_cond returns a ConditionVariable, and the example above calls while_wait and signal, this class should be documented.

Public Class Methods

new (monitor)
# File ext/monitor/lib/monitor.rb, line 146
def initialize(monitor)
  @monitor = monitor
  @cond = Thread::ConditionVariable.new
end

Public Instance Methods

broadcast ()

Wakes up all threads waiting for this lock.

# File ext/monitor/lib/monitor.rb, line 139
def broadcast
  @monitor.mon_check_owner
  @cond.broadcast
end
signal ()

Wakes up the first thread in line waiting for this lock.

# File ext/monitor/lib/monitor.rb, line 131
def signal
  @monitor.mon_check_owner
  @cond.signal
end
wait (timeout = nil)

Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.

If timeout is given, this method returns after timeout seconds passed, even if no other thread doesn’t signal.

# File ext/monitor/lib/monitor.rb, line 105
def wait(timeout = nil)
  @monitor.mon_check_owner
  @monitor.wait_for_cond(@cond, timeout)
end
wait_until ()

Calls wait repeatedly until the given block yields a truthy value.

# File ext/monitor/lib/monitor.rb, line 122
def wait_until
  until yield
    wait
  end
end
wait_while ()

Calls wait repeatedly while the given block yields a truthy value.

# File ext/monitor/lib/monitor.rb, line 113
def wait_while
  while yield
    wait
  end
end