On this page
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
# File lib/monitor.rb, line 156
def initialize(monitor)
@monitor = monitor
@cond = Thread::ConditionVariable.new
end
Public Instance Methods
# File lib/monitor.rb, line 149
def broadcast
@monitor.__send__(:mon_check_owner)
@cond.broadcast
end
Wakes up all threads waiting for this lock.
# File lib/monitor.rb, line 141
def signal
@monitor.__send__(:mon_check_owner)
@cond.signal
end
Wakes up the first thread in line waiting for this lock.
# File lib/monitor.rb, line 105
def wait(timeout = nil)
Thread.handle_interrupt(Exception => :never) do
@monitor.__send__(:mon_check_owner)
count = @monitor.__send__(:mon_exit_for_cond)
begin
Thread.handle_interrupt(Exception => :immediate) do
@cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
end
return true
ensure
@monitor.__send__(:mon_enter_for_cond, count)
end
end
end
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 lib/monitor.rb, line 132
def wait_until
until yield
wait
end
end
Calls wait repeatedly until the given block yields a truthy value.
# File lib/monitor.rb, line 123
def wait_while
while yield
wait
end
end
Calls wait repeatedly while the given block yields a truthy value.
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.