summaryrefslogtreecommitdiff
path: root/test/ruby/test_thread.rb
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-28 08:31:03 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-28 08:31:03 +0000
commit9cbf473287b6e0fca089c30db1cd276b3c2d477c (patch)
treeeb706d3be3d77b7830121a79905588fd091ceadc /test/ruby/test_thread.rb
parentb8a1e36201d3965b3f7b87fe1fa1cf55e00ce045 (diff)
* vm_core.h (enum rb_thread_status): remove THREAD_TO_KILL
* vm_core.h (struct rb_thread_struct): add to_kill field * thread.c (terminate_i): convert THREAD_TO_KILL to to_kill. * thread.c (rb_threadptr_to_kill): ditto. * thread.c (rb_thread_kill): ditto. * thread.c (rb_thread_wakeup_alive): ditto. * thread.c (thread_list_i): ditto. * thread.c (static const char): ditto. * thread.c (thread_status_name): ditto. * thread.c (rb_thread_status): ditto. * thread.c (rb_thread_inspect): ditto. * vm_backtrace.c (thread_backtrace_to_ary): ditto. * thread.c (rb_threadptr_execute_interrupts): fix thread status overwritten issue. [Bug #7450] [ruby-core:50249] * test/ruby/test_thread.rb (test_hread_status_raise_after_kill): test for the above. * test/ruby/test_thread.rb (test_thread_status_in_trap): test for thread status in trap. * test/ruby/test_thread.rb (test_status_and_stop_p): remove Thread.control_interrupt unsafe test. Thread#kill no longer changes thread status. Instead of, Thread#kill receiver changes their own status when receiving kill signal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_thread.rb')
-rw-r--r--test/ruby/test_thread.rb51
1 files changed, 43 insertions, 8 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 30e886447e..45f389b0fa 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -497,7 +497,6 @@ class TestThread < Test::Unit::TestCase
a = ::Thread.new { raise("die now") }
b = Thread.new { Thread.stop }
c = Thread.new { Thread.exit }
- d = Thread.new { sleep }
e = Thread.current
sleep 0.5
@@ -511,21 +510,14 @@ class TestThread < Test::Unit::TestCase
assert_match(/^#<TestThread::Thread:.* dead>$/, c.inspect)
assert(c.stop?)
- d.kill
- # to avoid thread switching...
- ds1 = d.status
- ds2 = d.stop?
es1 = e.status
es2 = e.stop?
- assert_equal(["aborting", false], [ds1, ds2])
-
assert_equal(["run", false], [es1, es2])
ensure
a.kill if a
b.kill if b
c.kill if c
- d.kill if d
end
def test_safe_level
@@ -912,4 +904,47 @@ Thread.new(Thread.current) {|mth|
}
INPUT
end
+
+ def test_thread_status_in_trap
+ # when running trap handler, Thread#status must show "run"
+ # Even though interrupted from sleeping function
+ assert_in_out_err([], <<-INPUT, %w(sleep run), [])
+ Signal.trap(:INT) {
+ puts Thread.current.status
+ }
+
+ Thread.new(Thread.current) {|mth|
+ sleep 0.01
+ puts mth.status
+ Process.kill(:INT, $$)
+ }
+ sleep 0.1
+ INPUT
+ end
+
+ # Bug #7450
+ def test_thread_status_raise_after_kill
+ ary = []
+
+ t = Thread.new {
+ begin
+ ary << Thread.current.status
+ sleep
+ ensure
+ begin
+ ary << Thread.current.status
+ sleep
+ ensure
+ ary << Thread.current.status
+ end
+ end
+ }
+
+ sleep 0.01
+ t.kill
+ sleep 0.01
+ t.raise
+ sleep 0.01
+ assert_equal(ary, ["run", "aborting", "aborting"])
+ end
end