1# one thread, one mutex (no contention) 2 3require 'thread' 4m = Mutex.new 5r = 0 6max = 2000 7lmax = max * max 8(1..1).map{ 9 Thread.new{ 10 i = 0 11 while i<lmax 12 i += 1 13 m.synchronize{ 14 r += 1 15 } 16 end 17 } 18}.each{|e| 19 e.join 20} 21raise r.to_s if r != max * max 22