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
Wake up all the waiters.
- #count_waiters ⇒ Object
-
#signal ⇒ Object
Wake up and run the next waiter.
-
#wait(timeout = nil) ⇒ Object
Create a new timer with the argument timeout, and add the current thread to the list of waiters.
-
#wait_until ⇒ Object
call #wait until the supplied block returns
true. -
#wait_while ⇒ Object
call #wait while the supplied block returns
true.
Instance Method Details
#broadcast ⇒ Object
Wake up all the waiters.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/monitor.rb', line 145 def broadcast @monitor.instance_eval {mon_check_owner()} Thread.critical = true for t in @waiters t.wakeup end @waiters.clear Thread.critical = false Thread.pass end |
#count_waiters ⇒ Object
156 157 158 |
# File 'lib/monitor.rb', line 156 def count_waiters return @waiters.length end |
#signal ⇒ Object
Wake up and run the next waiter
135 136 137 138 139 140 141 142 |
# File 'lib/monitor.rb', line 135 def signal @monitor.instance_eval {mon_check_owner()} Thread.critical = true t = @waiters.shift t.wakeup if t Thread.critical = false Thread.pass end |
#wait(timeout = nil) ⇒ Object
Create a new timer with the argument timeout, and add the current thread to the list of waiters. Then the thread is stopped. It will be resumed when a corresponding #signal occurs.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/monitor.rb', line 93 def wait(timeout = nil) @monitor.instance_eval {mon_check_owner()} timer = create_timer(timeout) Thread.critical = true count = @monitor.instance_eval {mon_exit_for_cond()} @waiters.push(Thread.current) begin Thread.stop return true rescue Timeout return false ensure Thread.critical = true if timer && timer.alive? Thread.kill(timer) end if @waiters.include?(Thread.current) # interrupted? @waiters.delete(Thread.current) end @monitor.instance_eval {mon_enter_for_cond(count)} Thread.critical = false end end |
#wait_until ⇒ Object
call #wait until the supplied block returns true.
128 129 130 131 132 |
# File 'lib/monitor.rb', line 128 def wait_until until yield wait end end |
#wait_while ⇒ Object
call #wait while the supplied block returns true.
121 122 123 124 125 |
# File 'lib/monitor.rb', line 121 def wait_while while yield wait end end |