Type:
Class

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'thread'
 
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
  }
}
signal
  • References/Ruby on Rails/Ruby/Classes/ConditionVariable

signal() Instance Public methods Wakes up the first thread in line waiting for

2025-01-10 15:47:30
wait
  • References/Ruby on Rails/Ruby/Classes/ConditionVariable

wait(mutex, timeout=nil) Instance Public methods Releases the lock held in mutex

2025-01-10 15:47:30
broadcast
  • References/Ruby on Rails/Ruby/Classes/ConditionVariable

broadcast() Instance Public methods Wakes up all threads waiting for this lock

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/ConditionVariable

new() Class Public methods Creates a new

2025-01-10 15:47:30