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

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 0.39 KB  |  hits: 11  |  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. a = ""
  2.  
  3. func1 = Proc.new do
  4.   i = 0
  5.   while i <= 100
  6.     puts "func1 "
  7.     sleep(0.001)
  8.     a.concat "aaaa"
  9.     i = i + 1
  10.   end
  11. end
  12. func2 = Proc.new do
  13.   i = 0
  14.   while i <= 100
  15.     puts "func2 "
  16.     sleep(0.001)
  17.     a.concat "bbbb"
  18.     i = i + 1
  19.   end
  20. end
  21.  
  22. puts "Start at: #{Time.now}"
  23. t1 = Thread.new{func1.call}
  24. t2 = Thread.new{func2.call}
  25. t1.join
  26. t2.join
  27. puts "a is #{a}"
  28. puts "End at: #{Time.now}"