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.
Class Methods
::
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 147
def initialize(monitor)
@monitor = monitor
@cond = Thread::ConditionVariable.new
end
No documentation available
Instance Methods
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 140
def broadcast
@monitor.mon_check_owner
@cond.broadcast
end
Wakes up all threads waiting for this lock.
#
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 132
def signal
@monitor.mon_check_owner
@cond.signal
end
Wakes up the first thread in line waiting for this lock.
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 106
def wait(timeout = nil)
@monitor.mon_check_owner
@monitor.wait_for_cond(@cond, timeout)
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.
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 123
def wait_until
until yield
wait
end
end
Calls wait repeatedly until the given block yields a truthy value.
ext/monitor/lib/monitor.rb
View on GitHub
# File tmp/rubies/ruby-3.1.3/ext/monitor/lib/monitor.rb, line 114
def wait_while
while yield
wait
end
end
Calls wait repeatedly while the given block yields a truthy value.