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