| Class | MonitorMixin::ConditionVariable |
| In: |
monitor.rb
|
| Parent: | Object |
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.
Wake up all the waiters.
# File monitor.rb, line 148 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
Wake up and run the next waiter
# File monitor.rb, line 138 def signal @monitor.instance_eval {mon_check_owner()} Thread.critical = true t = @waiters.shift t.wakeup if t Thread.critical = false Thread.pass end
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.
# File 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 begin 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)} ensure Thread.critical = false end end end
ruby-doc.org is a service of James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, AZ.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.