[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Thread interruptable too early?

Roger Pack

9/4/2007 9:47:00 PM

Hmm. Question.

Imagine you've got this code:
a = Thread.new {
begin
# do stuff
rescue MyException
end
}
a.raise MyException.new

Is it possible that this will still result in an uncaught exception
within thread a? Thoughts?
Thank you!
-Roger
--
Posted via http://www.ruby-....

1 Answer

Paul Brannan

9/4/2007 10:03:00 PM

0

On Wed, Sep 05, 2007 at 06:47:29AM +0900, Roger Pack wrote:
> Hmm. Question.
>
> Imagine you've got this code:
> a = Thread.new {
> begin
> # do stuff
> rescue MyException
> end
> }
> a.raise MyException.new
>
> Is it possible that this will still result in an uncaught exception
> within thread a? Thoughts?
> Thank you!
> -Roger
> --
> Posted via http://www.ruby-....

Thread#raise is bad, in general, for worse reasons than that:

t = Thread.new {
begin
allocate_resource()
do_something()
ensure
cleanup_resource()
end
}
sleep 1
t.raise SomeException.new

If the thread is in cleanup when Thread#raise is called, then cleanup
will fail, which is probably not the desired behavior.

There are plenty other examples I've seen as well.

Paul