[Bug #968] trap may fail to handle signals

Bug #968: trap may fail to handle signals
http://redmine.ruby-lang.org/issues/show/968

e$B5/I<<Te(B: Yusuke E.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Koichi Sasada, e$B%+%F%4%je(B: YARV, Target version: 1.9.1
RC2

e$B1sF#$G$9!#e(B

e$B%7%0%J%k$,O"B3$7$FAw$i$l$?$H$-!"%7%0%J%k$rFI$Mn$H$9$3$H$,e(B
e$B$"$k$h$&$G$9!#6qBNE*$K$O!"0J2<$N%W%m%0%i%`$,Dd;
$7$^$;$s!#e(B

./ruby -e ’
n = 0
trap(:USR1) { n += 1 }
30.times { Process.kill(:USR1, $$) }
until n == 30
1000**100000 # wait
p n
end

e$B$3$l$O;EMM$G$7$g$&$+!#e(B
e$B;EMM$G$J$1$l$P!"0J2<$N$h$&$J%Q%C%A$G$I$&$G$7$g$&$+!#e(B

Index: thread.c

— thread.c (revision 21269)
+++ thread.c (working copy)
@@ -1145,6 +1145,10 @@
void
rb_thread_execute_interrupts(rb_thread_t *th)
{

  • if (GET_VM()->main_thread == th) {

  • while (rb_signal_buff_size() && !th->exec_signal)
    native_thread_yield();

  • }

  • if (th->raised_flag) return;

    while (th->interrupt_flag) {
    @@ -2438,13 +2442,14 @@
    {
    rb_vm_t vm = GET_VM(); / TODO: fix me for Multi-VM */
    int sig;

  • rb_thread_t *mth;

    /* for time slice */
    RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread);

    /* check signal */

  • if ((sig = rb_get_next_signal()) > 0) {
  • rb_thread_t *mth = vm->main_thread;
  • mth = vm->main_thread;
  • if (!mth->exec_signal && (sig = rb_get_next_signal()) > 0) {
    enum rb_thread_status prev_status = mth->status;
    thread_debug(“main_thread: %s, sig: %d\n”,
    thread_status_name(prev_status), sig);


Yusuke ENDOH [email protected]

e$B%A%1%C%He(B #968 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B1sF#$G$9!#e(B

e$BJdB-$G$9!#e(B

e$B%7%0%J%k$,O"B3$7$FAw$i$l$?$H$-!"[email protected]$1%7%0%J%k%O%s%I%i$,8F$P$l$ke(B
e$B$H$$$&J]>c$Oe(B OS e$B%l%Y%k$GB8:_$7$J$$$HJ9$-$^$7$?!#e(B
[email protected]:#$Ne(B Ruby e$B$O!"$;$C$+$/%7%0%J%k%O%s%I%i$,8F$P$l$?>l9g$G$be(B
trap e$B$re(B
e$B8F$SB;$M$k>l9g$,$"$j$^$9!#e(B

e$B$^$?!"<oN`$,0[$J$k%7%0%J%k$G$be(B trap
e$B$r8F$SB;$M$k>l9g$,$"$k$N$G$9$,!"e(B
Unix e$B$G$O$3$l$9$iJ]>c$5$l$J$$$N$G$7$g$&$+!#e(B

$ ./ruby -e ’
n = 0
trap(:USR1) { n += 1 }
trap(:USR2) { n += 1 }

pid = $$
fork do
sleep 0.5
p “send start”
Process.kill(:USR1, pid)
Process.kill(:USR2, pid)
p “send end”
end

p “calc start”
1000**100000 # wait
p “calc end”

p n

“calc start”
“send start”
“send end”
“calc end”
1

e$B8=:_e(B test-all e$B$Ne(B TestSignal#test_exit_action
e$B$,7k9=$J3NN($G<:GT$7$^$9$,!"e(B
e$B$3$l$bF1$8LdBj$N$h$&$G!“A0=R$N%Q%C%A$rEv$F$k$HDL$k$h$&$K$J$j$^$9!#e(B
e$B;d$N4D6-$G9b3NN($Ge(B 0F0E e$B$K$J$k$N$G!”$&$l$7$$$G$9e(B (Rinda
e$B$N%F%9%H$,e(B
e$B5)$K<:GT$7$^$9$,e(B) e$B!#e(B

e$B$H$$$&$o$1$G!"@Q6KE*$JH?BP$,$J$1$l$P$H$j$"$($:%3%_%C%H$7$F$7$^$*$&e(B
e$B$H;W$$$^$9!#e(B


Yusuke ENDOH [email protected]


http://redmine.ruby-lang.org/issues/show/968

e$B%A%1%C%He(B #968 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r21582.

http://redmine.ruby-lang.org/issues/show/968

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs