Code

Ruby Thread#kill and ensure blocks

Here’s something interesting: If a thread is killed and the portion of code that was running has a corresponding ensure block, that block will be executed before the thread is killed. This is nice in that the utility of ensure is maintained (IO objects will be closed, etc.), but it’s perhaps unintuitive that the semantics of Thread.kill would allow for that. I suppose it’s like command line kill and not kill -9


2 Comments

Or leave out the t.join and get:

done!
ensuring

Posted by Andy Triggs on 1 November 2012 @ 11am

Very interesting. I thought that the opposite was true!

Posted by Jesse on 15 February 2013 @ 4pm

Leave a Comment