summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-05 19:37:37 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-05 19:37:37 +0000
commitdef63c3466939161f2459f6489815b444bbde8a3 (patch)
tree2d28e53a791ae47023aa2aa893e641896d08262a
parent84cfe8f8d669c3b8bdadc8a819d6482b890c5e24 (diff)
* io.c (io_binwrite): check interrupt before io issue.
* test/ruby/test_thread.rb (test_async_interrupt_and_io): test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--io.c3
-rw-r--r--test/ruby/test_thread.rb20
3 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 82d9e59a5c..c5b43d44d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Dec 6 04:27:10 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * 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@ruby-lang.org>
* vm_eval.c (rb_method_call_status): use Qundef as no self instead of
diff --git a/io.c b/io.c
index c678cc3b21..c8a5905630 100644
--- a/io.c
+++ b/io.c
@@ -1120,6 +1120,9 @@ io_binwrite(VALUE str, const char *ptr, long len, rb_io_t *fptr, int nosync)
{
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;
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 6bec7dfc34..b82cae4cb7 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -617,6 +617,26 @@ class TestThread < Test::Unit::TestCase
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){