Project

General

Profile

Actions

Backport #5757

closed

main threadがreadやselectで待っていると、^C でなかなか死なない

Added by naruse (Yui NARUSE) over 12 years ago. Updated about 12 years ago.


Description

FreeBSD 9 にて、 ./ruby と起動して ^C を投げてもなかなか死にません。
./miniruby でも -e'$stdin.read' でも同じです。

仕組みとしては、main thread が read や select で待つ場合、最近は blocking region で
unblock.func に ubf_select を設定するわけですが、この時にシグナルが来ると、

  1. どこかのスレッドの sighandler が呼ばれて、rb_thread_wakeup_timer_thread() が呼ばれる
  2. タイマースレッドが起きて、thread_timer() -> timer_thread_function() -> rb_threadptr_check_signal() -> rb_threadptr_interrupt() -> (th->unblock.func)(th->unblock.arg) -> ubf_select() -> rb_thread_wakeup_timer_thread() が呼ばれる
  3. タイマースレッドが起きて、thread_timer() -> timer_thread_function() -> rb_threadptr_check_signal() -> rb_threadptr_interrupt() -> (th->unblock.func)(th->unblock.arg) -> ubf_select() -> rb_thread_wakeup_timer_thread() が呼ばれる
  4. タイマースレッドが起きて、thread_timer() -> timer_thread_function() -> rb_threadptr_check_signal() -> rb_threadptr_interrupt() -> (th->unblock.func)(th->unblock.arg) -> ubf_select() -> rb_thread_wakeup_timer_thread() が呼ばれる
    ...

対策はいくつかあり得ると思うのですが、例えば、ubf_select() から rb_thread_wakeup_timer_thread() を呼ばないようにするとか


Files

bug5757.patch (1.26 KB) bug5757.patch nagachika (Tomoyuki Chikanaga), 12/14/2011 09:45 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #5343: Unexpected blocking behavior when interrupt Socket#acceptClosedko1 (Koichi Sasada)09/20/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0