On this page
End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class · Ruby 3.0
ConditionVariable
ConditionVariable objects augment class Mutex. Using condition variables, it is possible to suspend while in the middle of a critical section until a resource becomes available.
Example:
Example
mutex = Mutex.new resource = ConditionVariable.new a = Thread.new { mutex.synchronize { # Thread 'a' now needs the resource resource.wait(mutex) # 'a' can now have the resource } } b = Thread.new { mutex.synchronize { # Thread 'b' has finished using the resource resource.signal } }
Class methods 1
Instance methods 3
Ruby version changes 1
-
3.0
-
ConditionVariable#waitmay now invoke theblock/unblockscheduler hooks in a non-blocking context. [Feature #16786]
-