diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-28 01:51:44 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-28 01:51:44 +0000 |
commit | 6ec1720aa38772ba4b7515790443cb578340518b (patch) | |
tree | c9f5a56db84c7b47b12cf73e94f48dfdfbd80413 /test/monitor | |
parent | db7338fd7518b068269aa102e821ac388f519cd9 (diff) | |
download | ruby-6ec1720aa38772ba4b7515790443cb578340518b.tar.gz |
lib/monitor.rb: avoid race conditions by Thread.handle_interrupt
Suggested by Benoit Daloze. [ruby-core:88502] [Bug #14998]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/monitor')
-rw-r--r-- | test/monitor/test_monitor.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb index a036069647..8854b59ccc 100644 --- a/test/monitor/test_monitor.rb +++ b/test/monitor/test_monitor.rb @@ -269,4 +269,26 @@ class TestMonitor < Test::Unit::TestCase # end # cumber_thread.kill end + + def test_wait_interruption + queue = Queue.new + cond = @monitor.new_cond + @monitor.define_singleton_method(:mon_enter_for_cond) do |*args| + queue.deq + super(*args) + end + th = Thread.start { + @monitor.synchronize do + begin + cond.wait(0.1) + rescue Interrupt + @monitor.instance_variable_get(:@mon_owner) + end + end + } + sleep(0.1) + th.raise(Interrupt) + queue.enq(nil) + assert_equal th, th.value + end end |