From: Motohiro KOSAKI Date: 2011-12-21T23:26:43+09:00 Subject: [ruby-dev:45020] [ruby-trunk - Bug #5757][Assigned] main threadがreadやselectで待っていると、^C でなかなか死なない Issue #5757 has been updated by Motohiro KOSAKI. Status changed from Open to Assigned Assignee set to Motohiro KOSAKI すいません。なるべく早く時間取ってレビューします ---------------------------------------- Bug #5757: main threadがreadやselectで待っていると、^C でなかなか死なない https://bugs.ruby-lang.org/issues/5757 Author: Yui NARUSE Status: Assigned Priority: Normal Assignee: Motohiro KOSAKI 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