[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Thread#raise, Thread#kill, and timeout.rb are unsafe

Yukihiro Matsumoto

3/13/2008 4:03:00 PM

Hi,

In message "Re: Thread#raise, Thread#kill, and timeout.rb are unsafe"
on Mon, 25 Feb 2008 16:18:01 +0900, Charles Oliver Nutter <charles.nutter@sun.com> writes:

|I wrote up an article on Thread#raise, Thread#kill, and timeout.rb that
|I hope can start making the rounds. Long story short, neither
|Thread#raise nor Thread#kill is safe to use, and as a result all
|libraries that call them are also unsafe (including timeout.rb, net/*,
|and many other libraries in the wider world).

Unlike Java, Thread#raise etc. should be treated similar to
KeyboardInterrupt in Ruby. No realtime exception posting is expected.
If you handle KeyboardInterrupt safely, do same thing for Thread#raise
etc., e.g. just turning on flags to reserve exception, then raise
exception at the safe place, as MRI does. Nothing more is required.

I admit that timeout.rb is inefficient, so that it should not be used
when performance or completeness matters. I agree with removing use
of timeout from net/* libraries. It's just for casual use. Maybe
it's good to add a note in CAPITAL LETTERS in the document of
timeout.rb.

matz.

1 Answer

Paul Brannan

3/13/2008 9:01:00 PM

0

On Fri, Mar 14, 2008 at 01:02:52AM +0900, Yukihiro Matsumoto wrote:
> Unlike Java, Thread#raise etc. should be treated similar to
> KeyboardInterrupt in Ruby. No realtime exception posting is expected.
> If you handle KeyboardInterrupt safely, do same thing for Thread#raise
> etc., e.g. just turning on flags to reserve exception, then raise
> exception at the safe place, as MRI does. Nothing more is required.

I'm not convinced KeyboardInterrupt can be handled safely, either, in a
script. What happens if a KeyboardInterrupt exception is raised inside
an ensure block? It could easily result in resource leaks.

I think the right way to handle signals and timeouts is either in an
event loop or a dedicated thread. Asynchronous exceptions are
convenient but error-prone.

Paul