class Concurrent::Condition
the same mutex
Although it’s not mandatory, it’s recommended to call also #signal and #broadcast within
Every #wait must be guarded by a locked Mutex or a ThreadError will be risen.
by an another thread (using #signal or #broadcast) or due to timeout.
Condition::Result which make possible to know if waiting thread has been woken up
The biggest difference is the wait return value: Condition#wait returns
Condition is a better implementation of standard Ruby ConditionVariable.
def broadcast
-
(true)
-
def broadcast @condition.broadcast true end
def initialize
def initialize @condition = ConditionVariable.new end
def signal
-
(true)
-
def signal @condition.signal true end
def wait(mutex, timeout = nil)
-
(Result)
-
Parameters:
-
timeout
(Object
) -- nil means no timeout -
mutex
(Mutex
) -- the locked mutex guarding the wait
def wait(mutex, timeout = nil) start_time = Time.now.to_f @condition.wait(mutex, timeout) if timeout.nil? Result.new(nil) else Result.new(start_time + timeout - Time.now.to_f) end end