1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# -*- encoding: utf-8 -*-
require File.expand_path('./helper', File.dirname(__FILE__))
class TestRedBlackTree < Test::Unit::TestCase
def test_thread
h = ConcurrentRedBlackTree.new
num = 100000
max = 1000
threads = []
# writers
2.times do
threads << Thread.new {
num.times do
key = rand(max)
h[key] = key
end
}
end
# deleters
2.times do
threads << Thread.new {
num.times do
key = rand(max)
h.delete(key)
end
}
end
# readers
2.times do
threads << Thread.new {
num.times do
key = rand(max)
h[key]
end
}
end
threads.each(&:join)
end
end
|