Bug #7450

Thread#raise may override Thread#status unexpectedly

Added by Motohiro KOSAKI over 1 year ago. Updated over 1 year ago.

[ruby-core:50249]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI
Category:core
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-11-28 trunk 37921) [x86_64-linux] Backport:

Description

test.rb

ary = []

t = Thread.new {
begin
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

begin
sleep
ensure
p ary
end

expected result

["aborting", "aborting"]

actual result

["aborting", "run"]

reason

rbthreadptrexecute_interrupt() overides th->status unconditionally.

Associated revisions

Revision 37931
Added by Motohiro KOSAKI over 1 year ago

  • vmcore.h (enum rbthreadstatus): remove THREADTO_KILL
  • vmcore.h (struct rbthreadstruct): add tokill field
  • thread.c (terminatei): convert THREADTOKILL to tokill.
  • thread.c (rbthreadptrto_kill): ditto.
  • thread.c (rbthreadkill): ditto.
  • thread.c (rbthreadwakeup_alive): ditto.
  • thread.c (threadlisti): ditto.
  • thread.c (static const char): ditto.
  • thread.c (threadstatusname): ditto.
  • thread.c (rbthreadstatus): ditto.
  • thread.c (rbthreadinspect): ditto.
  • vmbacktrace.c (threadbacktracetoary): ditto.

  • thread.c (rbthreadptrexecute_interrupts): fix thread status
    overwritten issue. [Bug #7450]

  • test/ruby/testthread.rb (testhreadstatusraiseafterkill):
    test for the above.

  • test/ruby/testthread.rb (testthreadstatusin_trap): test for
    thread status in trap.

  • test/ruby/testthread.rb (teststatusandstopp): 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.

History

#1 Updated by Motohiro KOSAKI over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37931.
Motohiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vmcore.h (enum rbthreadstatus): remove THREADTO_KILL
  • vmcore.h (struct rbthreadstruct): add tokill field
  • thread.c (terminatei): convert THREADTOKILL to tokill.
  • thread.c (rbthreadptrto_kill): ditto.
  • thread.c (rbthreadkill): ditto.
  • thread.c (rbthreadwakeup_alive): ditto.
  • thread.c (threadlisti): ditto.
  • thread.c (static const char): ditto.
  • thread.c (threadstatusname): ditto.
  • thread.c (rbthreadstatus): ditto.
  • thread.c (rbthreadinspect): ditto.
  • vmbacktrace.c (threadbacktracetoary): ditto.

  • thread.c (rbthreadptrexecute_interrupts): fix thread status
    overwritten issue. [Bug #7450]

  • test/ruby/testthread.rb (testhreadstatusraiseafterkill):
    test for the above.

  • test/ruby/testthread.rb (testthreadstatusin_trap): test for
    thread status in trap.

  • test/ruby/testthread.rb (teststatusandstopp): 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.

Also available in: Atom PDF