# Problem with Mutex: Threads don't wakeup

**URL:** <https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901>\
**Category:** Ruby\
**Created:** [May 11, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901 "2007-05-11T14:23:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ce7236/32.png) [@laurent](https://www.ruby-forum.com/u/laurent)\
**Post date:** [May 11, 2007, 2:23pm UTC](https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901/1 "2007-05-11T14:23:41Z")

</div>

Hi all!

I am writting an application that runs about 100-200 threads that share  
a few specialized buffers. I am using the Mutex class to share the  
buffers between the different threads.

I am experiencing some weird problems where apparently some threads are  
waiting for the mutex and don’t get it even tho it is free. If I add a  
little ‘monitoring thread’ that wakes them up, it seems to work fine.

Anyone has some hints on what could go wrong?

I’ll be glad to give more information if needed…

Thanks!  
Laurent

---

<div class="post-metadata">

**Author:** ![laurent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ce7236/32.png) [@laurent](https://www.ruby-forum.com/u/laurent)\
**Post date:** [May 11, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901/2 "2007-05-11T18:47:54Z")

</div>

From: “Laurent” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I’ll be glad to give more information if needed…

Hi,

Are you using timeout{} or Thread#raise anywhere in your code? 🙂

Also, you might want to try installing the fastthread gem, which is a C  
implementation of thread.rb, just to see if the behavior you’re seeing  
changes at all. (Change require ‘thread’ to require ‘fastthread’…)  
[http://rubyforge.org/frs/?group\_id=1306&release\_id=10507](http://rubyforge.org/frs/?group_id=1306&release_id=10507)

Anyway, just some ideas… Otherwise, you may want to see if you  
can reproduce the problem in a small program, and post it here?

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![laurent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ce7236/32.png) [@laurent](https://www.ruby-forum.com/u/laurent)\
**Post date:** [May 11, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901/3 "2007-05-11T19:56:10Z")

</div>

On Sat, 12 May 2007 01:47:25 +0900, “Bill K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also, you might want to try installing the fastthread gem, which is a C  
> implementation of thread.rb, just to see if the behavior you’re seeing  
> changes at all. (Change require ‘thread’ to require ‘fastthread’…)  
> [http://rubyforge.org/frs/?group\_id=1306&release\_id=10507](http://rubyforge.org/frs/?group_id=1306&release_id=10507)

It’s actually best to require both thread and fastthread, catching the  
LoadError in the second case if fastthread is not installed (not all  
Ruby versions support or need fastthread).

It’s also important to note that if you’re using Ruby 1.8.6, fastthread  
fixes some bugs in the built-in mutex which could be responsible for the  
problems the OP was seeing.

-mental

---

<div class="post-metadata">

**Author:** ![laurent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ce7236/32.png) [@laurent](https://www.ruby-forum.com/u/laurent)\
**Post date:** [May 14, 2007, 10:36am UTC](https://www.ruby-forum.com/t/problem-with-mutex-threads-dont-wakeup/103901/4 "2007-05-14T10:36:28Z")

</div>

On 11.05.2007 14:23, Laurent wrote:

> Anyone has some hints on what could go wrong?
> 
> I’ll be glad to give more information if needed…

Yes, pleast post sme code - ideally a small sample that reproduces the  
behavior you are seeing.

Kind regards

robert
