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

Synchronize with simple variable assignment.

If it uses Queue, Mutex#synchronize may suppress the exception caused by
th.raise. The case happens when Ruby switches the thread after it pushes :go
into q, in `self.unlock rescue nil`. The exception is rescued the
`rescue nil`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2012-07-23 19:04:15 +00:00
parent fbee46fe66
commit 787c12da0b

View file

@ -618,23 +618,22 @@ class TestThread < Test::Unit::TestCase
def make_control_interrupt_test_thread1 flag def make_control_interrupt_test_thread1 flag
r = [] r = []
q = Queue.new ready_p = false
th = Thread.new{ th = Thread.new{
begin begin
Thread.control_interrupt(RuntimeError => flag){ Thread.control_interrupt(RuntimeError => flag){
q << :go
begin begin
ready_p = true
sleep 0.5 sleep 0.5
rescue rescue
r << :c1 r << :c1
end end
} }
sleep 0.5
rescue rescue
r << :c2 r << :c2
end end
} }
q.pop # wait Thread.pass until ready_p
th.raise th.raise
begin begin
th.join th.join