1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/thread.rb (Queue#push, #pop, SizedQueue#push, #pop): remove

code that kicks waiting thread twice, which caused race and
  deadlock.  [ruby-core:25537]

* test/thread/test_queue.rb: added.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2010-04-16 11:10:08 +00:00
parent 7d26c313a1
commit 93c5002a7c
3 changed files with 50 additions and 20 deletions

38
test/thread/test_queue.rb Normal file
View file

@ -0,0 +1,38 @@
require 'test/unit'
require 'thread'
class TestQueue < Test::Unit::TestCase
def test_queue
grind(5, 1000, 15, Queue)
end
def test_sized_queue
grind(5, 1000, 15, SizedQueue, 1000)
end
def grind(num_threads, num_objects, num_iterations, klass, *args)
from_workers = klass.new(*args)
to_workers = klass.new(*args)
workers = (1..num_threads).map {
Thread.new {
while object = to_workers.pop
from_workers.push object
end
}
}
Thread.new {
num_iterations.times {
num_objects.times { to_workers.push 99 }
num_objects.times { from_workers.pop }
}
}.join
num_threads.times { to_workers.push nil }
workers.each { |t| t.join }
assert 0, from_workers.size
assert 0, to_workers.size
end
end