Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.32 KB  |  hits: 2  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def what_you_want(i)
  2.   puts "hi #{i}"
  3.   sleep i
  4.   puts "bye #{i}"
  5. end
  6.  
  7. threads = []
  8. 3.times do |i| threads << Thread.new do
  9.     begin
  10.       what_you_want(i+1)
  11.       threads.each do |t|
  12.         t.kill! unless t == Thread.current
  13.       end
  14.     rescue
  15.       puts "uh-oh"
  16.     end
  17.   end
  18. end
  19. sleep 5
  20. puts "done"