Guest
Public paste!

Mark Aufflick

By: a guest | Dec 11th, 2007 | Syntax: None | Size: 0.30 KB | Hits: 24 | Expires: Never
Copy text to clipboard
  1. class Counter
  2.       attr_reader :count
  3.       def initialize
  4.           @count = 0;
  5.       end
  6.       def tick
  7.           @count += 1
  8.       end
  9. end
  10.  
  11. c = Counter.new
  12.  
  13. t1 = Thread.new { 10000.times { c.tick } }
  14. t2 = Thread.new { 10000.times { c.tick } }
  15.  
  16. t1.join
  17. t2.join
  18.  
  19. puts "#{c.count}"