# Fastthread crash (Was: Re: building Ruby with dmalloc)

**URL:** <https://www.ruby-forum.com/t/fastthread-crash-was-re-building-ruby-with-dmalloc/82267>\
**Category:** Ruby\
**Created:** [January 18, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/fastthread-crash-was-re-building-ruby-with-dmalloc/82267 "2007-01-18T17:11:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [January 18, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/fastthread-crash-was-re-building-ruby-with-dmalloc/82267/1 "2007-01-18T17:11:25Z")

</div>

On Wed, 2007-01-17 at 11:02 +0900, Young H. wrote:

> The program below reproduces the problem, and surprisingly, I only  
> use Mutex and ConditionVariable–no Queue.

I’ve reduced the test case you gave me down to:

```
    require 'fastthread'
    require 'thread'

    mutex = Mutex.new
    condition = ConditionVariable.new
    t = Thread.new do
      mutex.lock
      condition.wait mutex
    end
    exit

```

The problem, in this case, appears to be coping with the mutex and  
condition variable getting destroyed at program exit while there is  
still a thread waiting on the condition variable.

Simple waits on mutexes do not appear to be affected; for instance, this  
does not crash for me:

```
    require 'fastthread'
    require 'thread'

    mutex = Mutex.new
    mutex.lock
    t = Thread.new do
      mutex.lock
    end
    exit

```

I’m currently unsure whether it’s related to the other (non-exit-time)  
crash or not.

-mental

---

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [January 18, 2007, 5:37pm UTC](https://www.ruby-forum.com/t/fastthread-crash-was-re-building-ruby-with-dmalloc/82267/2 "2007-01-18T17:37:46Z")

</div>

On Fri, 2007-01-19 at 01:11 +0900, MenTaLguY wrote:

> The problem, in this case, appears to be coping with the mutex and  
> condition variable getting destroyed at program exit while there is  
> still a thread waiting on the condition variable.

Actually … that turns out to not be the problem. The thread is killed  
and the wait queue empty by the time the condition variable is  
finalized.

Bizzarely, what appears to be happening is that rb\_queue\_alloc is  
getting called when creating mutexes and condition variables. Hence  
free\_queue is getting called when mutexes and condition variables are  
destroyed, and chaos ensues.

At least it’s a simple problem, but it’s a WEIRD one.

-mental

---

<div class="post-metadata">

**Author:** ![MenTaLguY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@MenTaLguY](https://www.ruby-forum.com/u/MenTaLguY)\
**Post date:** [January 18, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/fastthread-crash-was-re-building-ruby-with-dmalloc/82267/3 "2007-01-18T19:32:47Z")

</div>

It turns out that the fastthread crash is due to a bug in the Ruby  
interpreter’s handling of allocator functions for anonymous classes:

[http://rubyforge.org/tracker/index.php?func=detail&aid=7974&group\_id=426&atid=1698](http://rubyforge.org/tracker/index.php?func=detail&aid=7974&group_id=426&atid=1698)

I will try to come up with a workaround.

-mental
