Parent

Files

Class/Module Index [+]

Quicksearch

Concurrent::Condition

Condition is a better implementation of standard Ruby ConditionVariable. The biggest difference is the wait return value: Condition#wait returns Condition::Result which make possible to know if waiting thread has been woken up by an another thread (using signal or broadcast) or due to timeout.

Every wait must be guarded by a locked Mutex or a ThreadError will be risen. Although it's not mandatory, it's recommended to call also signal and broadcast within the same mutex

@deprecated

Public Class Methods

new() click to toggle source
# File lib/concurrent/atomic/condition.rb, line 43
def initialize
  deprecated 'Will be replaced with Synchronization::Object in v1.0.'
  @condition = ConditionVariable.new
end

Public Instance Methods

broadcast() click to toggle source

Wakes up all waiting threads @return [true]

# File lib/concurrent/atomic/condition.rb, line 73
def broadcast
  @condition.broadcast
  true
end
signal() click to toggle source

Wakes up a waiting thread @return [true]

# File lib/concurrent/atomic/condition.rb, line 66
def signal
  @condition.signal
  true
end
wait(mutex, timeout = nil) click to toggle source

@param [Mutex] mutex the locked mutex guarding the wait @param [Object] timeout nil means no timeout @return [Result]

@!macro monotonic_clock_warning

# File lib/concurrent/atomic/condition.rb, line 53
def wait(mutex, timeout = nil)
  start_time = Concurrent.monotonic_time
  @condition.wait(mutex, timeout)

  if timeout.nil?
    Result.new(nil)
  else
    Result.new(start_time + timeout - Concurrent.monotonic_time)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.