Class: MonitorMixin::ConditionVariable
- Inherits:
-
Object
- Object
- MonitorMixin::ConditionVariable
- Defined in:
- lib/monitor.rb
Overview
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.
Defined Under Namespace
Classes: Timeout
Instance Method Summary collapse
-
#broadcast ⇒ Object
Wakes up all threads waiting for this lock.
-
#signal ⇒ Object
Wakes up the first thread in line waiting for this lock.
-
#wait(timeout = nil) ⇒ Object
Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
-
#wait_until ⇒ Object
Calls wait repeatedly until the given block yields a truthy value.
-
#wait_while ⇒ Object
Calls wait repeatedly while the given block yields a truthy value.
Instance Method Details
#broadcast ⇒ Object
Wakes up all threads waiting for this lock.
146 147 148 149 |
# File 'lib/monitor.rb', line 146 def broadcast @monitor.__send__(:mon_check_owner) @cond.broadcast end |
#signal ⇒ Object
Wakes up the first thread in line waiting for this lock.
138 139 140 141 |
# File 'lib/monitor.rb', line 138 def signal @monitor.__send__(:mon_check_owner) @cond.signal end |
#wait(timeout = nil) ⇒ Object
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.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/monitor.rb', line 106 def wait(timeout = nil) @monitor.__send__(:mon_check_owner) count = @monitor.__send__(:mon_exit_for_cond) begin @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout) return true ensure @monitor.__send__(:mon_enter_for_cond, count) end end |
#wait_until ⇒ Object
Calls wait repeatedly until the given block yields a truthy value.
129 130 131 132 133 |
# File 'lib/monitor.rb', line 129 def wait_until until yield wait end end |
#wait_while ⇒ Object
Calls wait repeatedly while the given block yields a truthy value.
120 121 122 123 124 |
# File 'lib/monitor.rb', line 120 def wait_while while yield wait end end |