# Code Review: ThreadLib

**URL:** <https://www.ruby-forum.com/t/code-review-threadlib/137784>\
**Category:** IronRuby\
**Created:** [May 16, 2008, 10:56am UTC](https://www.ruby-forum.com/t/code-review-threadlib/137784 "2008-05-16T10:56:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 16, 2008, 10:56am UTC](https://www.ruby-forum.com/t/code-review-threadlib/137784/1 "2008-05-16T10:56:23Z")

</div>

atfpt review /shelveset:ThreadLib;REDMOND\tomat

A rough implementation of thread.so.

Ignores differences of Ruby Mutex and .NET Monitor for now:

- Ruby Mutex.lock in not reentrant by the same thread
- it could be locked/unlocked from non-owning thread (.NET Monitor  
throws an exception in that case)

Also IronRuby runtime itself is not hardened against race conditions  
yet.

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [May 26, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/code-review-threadlib/137784/2 "2008-05-26T19:48:17Z")

</div>

On Thu, 2008-05-15 at 21:03 -0700, Tomas M. wrote:

> - it could be locked/unlocked from non-owning thread (.NET Monitor  
> throws an exception in that case)

Don’t worry about supporting that case.

Most of the people who abused Mutex by trying to use it like a semaphore  
have been weeded out since I modified fastthread to raise an exception  
for unlocks by non-owners.

(I believe the latest 1.8.6 patchlevels also throw an exception, if  
you’re using the C Mutex implementation which is based on fastthread.)

-mental
