Project

General

Profile

Actions

Bug #968

closed

trap may fail to handle signals

Added by mame (Yusuke Endoh) almost 16 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
Backport:
[ruby-dev:37676]

Description

=begin
遠藤です。

シグナルが連続して送られたとき、シグナルを読み落とすことが
あるようです。具体的には、以下のプログラムが停止しません。

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

これは仕様でしょうか。
仕様でなければ、以下のようなパッチでどうでしょうか。

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
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0