Ruby/Threads/kill
Материал из Wiki.crossplatform.ru
Версия от 17:59, 13 сентября 2010; ViGOur (Обсуждение | вклад)
Kill a thread and pass execution to another thread
t1 = Thread.new { sleep 100 } t2 = Thread.new do if Thread.current == Thread.main puts "This is the main thread." # Does NOT print end 1.upto(1000) sleep 0.1 end end Thread.kill(t1) Thread.pass(t2) # Pass execution to t2 now t3 = Thread.new do sleep 20 Thread.exit puts "Can"t happen!" end Thread.kill(t2) # Now exit the main thread (killing any others) Thread.exit