# Code Review: Issues with Thread#kill and raising exception from ensure clause

**URL:** <https://www.ruby-forum.com/t/code-review-issues-with-thread-kill-and-raising-exception-from-ensure-clause/157365>\
**Category:** IronRuby\
**Created:** [January 10, 2009, 12:47am UTC](https://www.ruby-forum.com/t/code-review-issues-with-thread-kill-and-raising-exception-from-ensure-clause/157365 "2009-01-10T00:47:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [January 10, 2009, 12:47am UTC](https://www.ruby-forum.com/t/code-review-issues-with-thread-kill-and-raising-exception-from-ensure-clause/157365/1 "2009-01-10T00:47:29Z")

</div>

tfpt review “/shelveset:kill;REDMOND\sborde”

Comment :  
Added more tests for Thread#kill, and fixed bugs that were exposed.  
Throwing an exception from the ensure clause exposes new code paths.

Ruby allows Thread#kill to be completely subverted (not just deferred  
as an infinite loop in an ensure clause would do) by raising an  
exception from a ensure clause. I have not matched that behavior, and  
left it as a IronRuby bug for now.

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [January 10, 2009, 2:19am UTC](https://www.ruby-forum.com/t/code-review-issues-with-thread-kill-and-raising-exception-from-ensure-clause/157365/2 "2009-01-10T02:19:56Z")

</div>

Are any methods in RubyOps Exceptions #region (including those added by  
this shelveset) emitted to IL? If not they should rather be in RubyUtils  
class.

On the other hand, SourceUnitTree.CheckForAsyncRaiseViaThreadAbortshould  
should be marked as [Emitted], be in RubyOps.cs and  
SourceUnitTree.GenerateCheckForAsyncException should use  
Methods.CheckForAsyncRaiseViaThreadAbort to get the method.

Could we add a public helper that calls thread.Abort(new  
ThreadExitMarker()); move the private ThreadExitMarker class and  
IsRubyThreadExit to RubyUtils? Then we won’t need to duplicate the  
marker class in ThreadOps?

Other than that, looks good.

Tomas

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [January 10, 2009, 7:29am UTC](https://www.ruby-forum.com/t/code-review-issues-with-thread-kill-and-raising-exception-from-ensure-clause/157365/3 "2009-01-10T07:29:12Z")

</div>

Inline…
