Thread interruptable too early?

R

Roger Pack

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
 
P

Paul Brannan

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Is $! thread safe? 7
Thread pool issue 1
Thread deadlock 8
Is thread dead? 0
how many thread?! 1
Net::Imap thread safety 0
ruby wish-list 170
Weird thread behavior in windows. 1

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top