From: Tomoyuki Chikanaga Date: 2011-12-22T22:47:48+09:00 Subject: [ruby-dev:45032] [ruby-trunk - Bug #5757][Closed] main threadがreadやselectで待っていると、^C でなかなか死なない Issue #5757 has been updated by Tomoyuki Chikanaga. Status changed from Assigned to Closed ---------------------------------------- Bug #5757: main threadがreadやselectで待っていると、^C でなかなか死なない https://bugs.ruby-lang.org/issues/5757 Author: Yui NARUSE Status: Closed Priority: Normal Assignee: Tomoyuki Chikanaga Category: Target version: ruby -v: - 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() を呼ばないようにするとか -- http://redmine.ruby-lang.org