2011-06-13 18:05:56 +04:00
|
|
|
# two threads, one mutex
|
|
|
|
|
|
|
|
require 'thread'
|
2016-08-30 09:22:30 +03:00
|
|
|
m = Thread::Mutex.new
|
2011-06-13 18:05:56 +04:00
|
|
|
r = 0
|
2011-07-01 14:39:12 +04:00
|
|
|
max = 2000
|
2011-06-13 18:05:56 +04:00
|
|
|
lmax = (max * max)/2
|
|
|
|
(1..2).map{
|
|
|
|
Thread.new{
|
2012-05-27 18:41:01 +04:00
|
|
|
i = 0
|
2011-06-13 18:05:56 +04:00
|
|
|
while i<lmax
|
2012-10-15 16:53:12 +04:00
|
|
|
i += 1
|
2011-06-13 18:05:56 +04:00
|
|
|
m.synchronize{
|
|
|
|
r += 1
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}.each{|e|
|
|
|
|
e.join
|
|
|
|
}
|
|
|
|
raise r.to_s if r != max * max
|