Class: MonitorMixin::ConditionVariable (Ruby 2.2.2)
Description: Class : MonitorMixin::ConditionVariable - Ruby 2.2.2

- Home
- Core 2.2.2
- Std-lib 2.2.2
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- monitor.rb

### Parent

Object

### Namespace

- CLASS MonitorMixin::ConditionVariable::Timeout

### Methods

- ::new
- #broadcast
- #signal
- #wait
- #wait_until
- #wait_while

### Class/Module Index

Quicksearch

- Monitor
- MonitorMixin
- MonitorMixin::ConditionVariable
- MonitorMixin::ConditionVariable::Timeout

No matching classes.

# MonitorMixin::ConditionVariable

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.

### Public Class Methods

new(monitor) click to toggle source

                   # File monitor.rb, line 153
    def initialize(monitor)
      @monitor = monitor
      @cond = ::ConditionVariable.new
    end

### Public Instance Methods

broadcast() click to toggle source

Wakes up all threads waiting for this lock.

                   # File monitor.rb, line 146
    def broadcast
      @monitor.__send__(:mon_check_owner)
      @cond.broadcast
    end

signal() click to toggle source

Wakes up the first thread in line waiting for this lock.

                   # File monitor.rb, line 138
    def signal
      @monitor.__send__(:mon_check_owner)
      @cond.signal
    end

wait(timeout = nil) click to toggle source

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.

                   # File 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() click to toggle source

Calls wait repeatedly until the given block yields a truthy value.

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

wait_while() click to toggle source

Calls wait repeatedly while the given block yields a truthy value.

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