ruby-changes:26167
From: kosaki <ko1@a...>
Date: Thu, 6 Dec 2012 04:37:49 +0900 (JST)
Subject: [ruby-changes:26167] kosaki:r38224 (trunk): * io.c (io_binwrite): check interrupt before io issue.
kosaki 2012-12-06 04:37:37 +0900 (Thu, 06 Dec 2012) New Revision: 38224 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38224 Log: * io.c (io_binwrite): check interrupt before io issue. * test/ruby/test_thread.rb (test_async_interrupt_and_io): test for the above. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_thread.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38223) +++ ChangeLog (revision 38224) @@ -1,3 +1,9 @@ +Thu Dec 6 04:27:10 2012 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (io_binwrite): check interrupt before io issue. + * test/ruby/test_thread.rb (test_async_interrupt_and_io): + test for the above. + Thu Dec 6 01:10:36 2012 Nobuyoshi Nakada <nobu@r...> * vm_eval.c (rb_method_call_status): use Qundef as no self instead of Index: io.c =================================================================== --- io.c (revision 38223) +++ io.c (revision 38224) @@ -1120,6 +1120,9 @@ { long n, r, offset = 0; + /* don't write anything if current thread has a pending interrupt. */ + rb_thread_check_ints(); + if ((n = len) <= 0) return n; if (fptr->wbuf.ptr == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) { fptr->wbuf.off = 0; Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 38223) +++ test/ruby/test_thread.rb (revision 38224) @@ -617,6 +617,26 @@ assert_equal(:ok,r) end + def test_async_interrupt_and_io + assert_in_out_err([], <<-INPUT, %w(ok), []) + th_waiting = true + + t = Thread.new { + Thread.async_interrupt_timing(RuntimeError => :on_blocking) { + nil while th_waiting + # async interrupt should be raised _before_ writing puts arguments + puts "ng" + } + } + + sleep 0.1 + t.raise RuntimeError + th_waiting = false + t.join rescue nil + puts "ok" + INPUT + end + def test_async_interrupted? q = Queue.new Thread.async_interrupt_timing(RuntimeError => :defer){ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/