summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-28 01:51:44 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-28 01:51:44 +0000
commit6ec1720aa38772ba4b7515790443cb578340518b (patch)
treec9f5a56db84c7b47b12cf73e94f48dfdfbd80413 /lib
parentdb7338fd7518b068269aa102e821ac388f519cd9 (diff)
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 'lib')
-rw-r--r--lib/monitor.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 288ed755ea..2a59fa7cc0 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -103,13 +103,17 @@ module MonitorMixin
# even if no other thread doesn't signal.
#
def wait(timeout = nil)
- @monitor.__send__(:mon_check_owner)
- count = @monitor.__send__(:mon_exit_for_cond)
- begin
- @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
- return true
- ensure
- @monitor.__send__(:mon_enter_for_cond, count)
+ Thread.handle_interrupt(Exception => :never) do
+ @monitor.__send__(:mon_check_owner)
+ count = @monitor.__send__(:mon_exit_for_cond)
+ begin
+ Thread.handle_interrupt(Exception => :immediate) do
+ @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
+ end
+ return true
+ ensure
+ @monitor.__send__(:mon_enter_for_cond, count)
+ end
end
end