From: Yusuke ENDOH Date: 2011-01-19T19:32:45+09:00 Subject: [ruby-core:34598] Re: [Ruby 1.9-Bug#4283] Timeout.timeout may cause application exit unintetionally Hi, 2011/1/19 Charles Oliver Nutter : > JRuby implements Thread#raise and #kill using exactly this mechanism. > On boundaries roughly equivalent to MRI 1.8's thread context switches, > we ping thread state to see if a kill or raise event has been sent to > the thread. I guess that you misunderstand cancellation points. They do not mean context-switch boundaries. Usually, an operation that may suspend the execution is defined as cancellation points, such as blocking I/O, synchronization and sleep. In terms of Ruby, they roughly mean any operation that may change Thread#status to "sleep", such as IO#read, Mutex#lock, and sleep. It is important for a programmer to be able to control whether his own program contains cancellation points or not. > I must reiterate, however, that this is only a band-aid. Because Ruby > is not "functionally pure", a top-level method might wrap everything > in an ensure block. Should the entire application disable kill/raise? No, not at all. According to that mechanism, asynchronous exceptions are raised when you run any calcellation point operation, even when asynchronous exceptions are prohibited. begin ensure foo.bar # an Interrupt may not be raised # (unless these methods do not contain cancellation points) sleep 1 # cancellation point; an Interrupt may be raised here baz.qux # an Interrupt may not be raised end -- Yusuke Endoh