Сигналы


#!/usr/bin/ruby

# Signals

require 'thread'
mutex = Mutex.new
cv = ConditionVariable.new

puts "Process 1"
a = Thread.new {
  mutex.synchronize {
    puts "A: Wait For Signal"
    cv.wait(mutex)
    puts "A: All done!"
  }
}

puts "Process 2"
b = Thread.new {
  mutex.synchronize {
    puts "B: Sending signal to A"
    cv.signal
    puts "B: All done!"
  }
}
a.join
b.join