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

Join threads.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-31 15:31:46 +00:00
parent 06fb823435
commit 6f6dd30dbf
3 changed files with 12 additions and 6 deletions

View file

@ -86,7 +86,7 @@ class TestMonitor < Test::Unit::TestCase
def test_try_enter def test_try_enter
queue1 = Queue.new queue1 = Queue.new
queue2 = Queue.new queue2 = Queue.new
Thread.start { th = Thread.start {
queue1.deq queue1.deq
@monitor.enter @monitor.enter
queue2.enq(nil) queue2.enq(nil)
@ -102,6 +102,7 @@ class TestMonitor < Test::Unit::TestCase
queue1.enq(nil) queue1.enq(nil)
queue2.deq queue2.deq
assert_equal(true, @monitor.try_enter) assert_equal(true, @monitor.try_enter)
th.join
end end
def test_cond def test_cond
@ -109,7 +110,7 @@ class TestMonitor < Test::Unit::TestCase
a = "foo" a = "foo"
queue1 = Queue.new queue1 = Queue.new
Thread.start do th = Thread.start do
queue1.deq queue1.deq
@monitor.synchronize do @monitor.synchronize do
a = "bar" a = "bar"
@ -123,13 +124,14 @@ class TestMonitor < Test::Unit::TestCase
assert_equal(true, result1) assert_equal(true, result1)
assert_equal("bar", a) assert_equal("bar", a)
end end
th.join
end end
def test_timedwait def test_timedwait
cond = @monitor.new_cond cond = @monitor.new_cond
b = "foo" b = "foo"
queue2 = Queue.new queue2 = Queue.new
Thread.start do th = Thread.start do
queue2.deq queue2.deq
@monitor.synchronize do @monitor.synchronize do
b = "bar" b = "bar"
@ -143,10 +145,11 @@ class TestMonitor < Test::Unit::TestCase
assert_equal(true, result2) assert_equal(true, result2)
assert_equal("bar", b) assert_equal("bar", b)
end end
th.join
c = "foo" c = "foo"
queue3 = Queue.new queue3 = Queue.new
Thread.start do th = Thread.start do
queue3.deq queue3.deq
@monitor.synchronize do @monitor.synchronize do
c = "bar" c = "bar"
@ -163,6 +166,7 @@ class TestMonitor < Test::Unit::TestCase
assert_equal(true, result4) assert_equal(true, result4)
assert_equal("bar", c) assert_equal("bar", c)
end end
th.join
# d = "foo" # d = "foo"
# cumber_thread = Thread.start { # cumber_thread = Thread.start {

View file

@ -124,7 +124,7 @@ class TestFile < Test::Unit::TestCase
q1 = Queue.new q1 = Queue.new
q2 = Queue.new q2 = Queue.new
Thread.new do th = Thread.new do
data = '' data = ''
64.times do |i| 64.times do |i|
data << i.to_s data << i.to_s
@ -142,6 +142,7 @@ class TestFile < Test::Unit::TestCase
assert_equal size, f.size assert_equal size, f.size
q2.push true q2.push true
end end
th.join
end end
end end

View file

@ -1237,8 +1237,9 @@ class TestProcess < Test::Unit::TestCase
IO.pipe do |r, w| IO.pipe do |r, w|
pid = spawn(RUBY, "foo", out: w) pid = spawn(RUBY, "foo", out: w)
w.close w.close
Thread.new { r.read(1); Process.kill(:SIGQUIT, pid) } th = Thread.new { r.read(1); Process.kill(:SIGQUIT, pid) }
Process.wait(pid) Process.wait(pid)
th.join
end end
t = Time.now t = Time.now
s = $? s = $?