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.

### Methods

broadcast count_waiters new signal wait wait_until wait_while

### Classes and Modules

Class MonitorMixin::ConditionVariable::Timeout

### Public Class methods

new(monitor)

[Source]

    # File monitor.rb, line 153
        def initialize(monitor)
          @monitor = monitor
          @waiters = []
        end

### Public Instance methods

broadcast()

[Source]

    # File monitor.rb, line 136
        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()

[Source]

    # File monitor.rb, line 147
        def count_waiters
          return @waiters.length
        end

signal()

[Source]

    # File monitor.rb, line 127
        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)

[Source]

    # File monitor.rb, line 89
        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()

[Source]

    # File monitor.rb, line 121
        def wait_until
          until yield
            wait
          end
        end

wait_while()

[Source]

    # File monitor.rb, line 115
        def wait_while
          while yield
            wait
          end
        end

[Validate]