Ruby/Threads/wakeup

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Wake up a thread

t1 = Thread.new do
  Thread.stop
  puts "There is an emerald here."
end
t2 = Thread.new do
  Thread.stop
  puts "You"re at Y2."
end
sleep 1
t1.wakeup
t2.run



Wakeup main thread

alarm = Thread.new(self) { sleep(5); Thread.main.wakeup }
puts "sleep for 1000 seconds at #{Time.new}"
sleep(10000); puts "Woke up at #{Time.new}!"