# Deadlock falsely detected when using condition variables

**URL:** <https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657>\
**Category:** Ruby\
**Created:** [September 27, 2007, 9:25am UTC](https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657 "2007-09-27T09:25:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [September 27, 2007, 9:25am UTC](https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657/1 "2007-09-27T09:25:34Z")

</div>

I have a fragment of multi-threaded code using Ruby’s Mutex and  
ConditionVariable class, where it appears that the interpreter  
is calling a deadlock incorrectly.

I’m using ruby 1.8.6 on Windows XP.

The code in question looks like this:

@mutex = Mutex.new  
@condition = ConditionVariable.new

@mutex.synchronize {  
@condition.wait(@mutex) until @data\_ready  
… use data…  
@data\_ready = false  
}

And the producer thread says:

@mutex.synchronize {  
… make data available…  
@data\_ready = true  
@condition.signal  
}

Now sometimes the call to synchronize in the producer cause a deadlock,  
which shows the two threads to be both sleeping, one in the condition  
wait, one in the producer’s synchronise call.

This should never happen… the condition is meant to atomically release  
the mutex as it goes to sleep.

Whats happening here folk?

Clifford H…

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [September 27, 2007, 9:41am UTC](https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657/2 "2007-09-27T09:41:58Z")

</div>

> Whats happening here folk?  
> What patchlevel of 1.8.6 are you using ? 1.8.6-p0 is completely broken  
> w.r.t. thread support. 1.8.6 p36 and p110 are better.

Sylvain

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [September 28, 2007, 1:25am UTC](https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657/3 "2007-09-28T01:25:40Z")

</div>

Clifford H. wrote:

> > What patchlevel of 1.8.6 are you using ? 1.8.6-p0 is completely broken  
> > w.r.t. thread support. 1.8.6 p36 and p110 are better.

My ruby -v said p0, but the install actually came from the latest  
one-click  
installer, which calls itself 186-25. I don’t know what the -25 means,  
but  
there seems to be no newer one-click installer.

Do I have to build the current ruby from source, or is there a newer  
one-click installer?

Clifford H…

---

<div class="post-metadata">

**Author:** ![Clifford\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/49beb7/32.png) [@Clifford\_H](https://www.ruby-forum.com/u/Clifford_H)\
**Post date:** [September 27, 2007, 9:55am UTC](https://www.ruby-forum.com/t/deadlock-falsely-detected-when-using-condition-variables/115657/4 "2007-09-27T09:55:49Z")

</div>

Sylvain J. wrote:

> > Whats happening here folk?  
> > What patchlevel of 1.8.6 are you using ? 1.8.6-p0 is completely broken  
> > w.r.t. thread support. 1.8.6 p36 and p110 are better.

Craaap! It’s patch -p0! How can such a fundamental thing be so  
catastrophically broken?  
Are there no test suites? I’ve been blaming myself for three hours  
now…

Thanks for much for setting me straight… I’ll get a new version right  
away.

Clifford H…
