ruby-changes:45406
From: ko1 <ko1@a...>
Date: Tue, 31 Jan 2017 16:00:42 +0900 (JST)
Subject: [ruby-changes:45406] ko1:r57479 (trunk): allow Queue operation in trap.
ko1 2017-01-31 16:00:38 +0900 (Tue, 31 Jan 2017) New Revision: 57479 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57479 Log: allow Queue operation in trap. * thread_sync.c: allow spurious wakeup to check Queue status just after trap. [Bug #12405] * test/thread/test_queue.rb: add a test for it. Modified files: trunk/test/thread/test_queue.rb trunk/thread_sync.c Index: test/thread/test_queue.rb =================================================================== --- test/thread/test_queue.rb (revision 57478) +++ test/thread/test_queue.rb (revision 57479) @@ -547,4 +547,21 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L547 # don't leak this thread assert_nothing_raised{counter.join} end + + def test_queue_with_trap + assert_in_out_err([], <<-INPUT, %w(USR2 USR2 exit), []) + q = Queue.new + trap(:USR2){ + q.push 'USR2' + } + Thread.new{ + loop{ + Process.kill :USR2, $$ + } + } + puts q.pop + puts q.pop + puts 'exit' + INPUT + end end Index: thread_sync.c =================================================================== --- thread_sync.c (revision 57478) +++ thread_sync.c (revision 57479) @@ -773,7 +773,7 @@ queue_delete_from_waiting(struct waiting https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L773 static VALUE queue_sleep(VALUE arg) { - rb_thread_sleep_deadly(); + rb_thread_sleep_deadly_allow_spurious_wakeup(); return Qnil; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/