# \[BUG\] queue 0x424010 freed with live thread(s) waiting

**URL:** <https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444>\
**Category:** Development\
**Created:** [March 20, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444 "2007-03-20T14:50:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masatoshi\_SEKI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@Masatoshi\_SEKI](https://www.ruby-forum.com/u/Masatoshi_SEKI)\
**Post date:** [March 20, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444/1 "2007-03-20T14:50:44Z")

</div>

e$B31$H$$$$$^$9!#e(B

e$B=PCY$l$F$7$^$$$^$7$?$,!"$d$C$He(Bsvne$BHG$r;n$7;O$a$^$7$?!#e(B

1.8e$B7O$N%V%i%s%A$Oe(Bruby\_1\_8e$B$G$h$$$N$G$7$?$C$1e(B?

e$B\<!$N%9%/%j%W%H$N$h$&$Je(BQueuee$B$rBT$C$F$k%9%l%C%I$,$"$k\>uBV$Ge(B  
e$B%a%$%s%9%l%C%I$,=\*N;$9$k%1!\<%9$Ge(B  
[BUG] queue 0x424010 freed with live thread(s) waiting  
e$B$H$J$j$^$7$?!#e(B

e$B:F8=$7$?$N$O$3$NHG$G$9!#G[I[$5$l$F$$$ke(B1.8.6e$B$G$OLdBj$"$j$^$;$s!#e(B ruby 1.8.6 (2007-03-20 patchlevel 5000) [powerpc-darwin8.9.0]

-----lb.rb------

require ‘thread’

class LocalBarrier  
def initialize(n)  
@wait = Queue.new  
@done = Queue.new  
@keeper = begin\_keeper(n)  
end

def sync  
@done.push(true)  
@wait.pop  
end

def join  
@keeper.join  
end

private  
def begin\_keeper(n)  
Thread.start do  
n.times do  
@done.pop  
end  
n.times do  
@wait.push(true)  
end  
end  
end  
end

n = 10

lb = LocalBarrier.new(n)

(n - 1).times do |i|  
Thread.start do  
sleep(rand(n) + 1)  
puts “#{i}: done”  
lb.sync  
puts “#{i}: cont”  
end  
end

lb.sync  
puts “#{n-1}: cone”

# lb.join # \<-- e$B$3$l$r%3%a%s%H%"%&%H$9$k$H:F8=$7$^$9!#e(B

puts “exit.”

* * *

svne$BHG$G$O\<!$NDL$j\<:GT$7$^$9!#e(B

four: mas$ ruby -dv lb.rb  
ruby 1.8.6 (2007-03-20 patchlevel 5000) [powerpc-darwin8.9.0]  
1: done  
5: done  
8: done  
3: done  
2: done  
7: done  
0: done  
6: done  
4: done  
9: cone  
exit.  
lc.rb:50: [BUG] queue 0x424010 freed with live thread(s) waiting  
ruby 1.8.6 (2007-03-20) [powerpc-darwin8.9.0]

Abort trap

e$BG[I[$5$l$F$$$ke(B1.8.6e$B$G$OLdBj$"$j$^$;$s!#e(B

four: mas$ ruby -dv lb.rb  
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]  
1: done  
7: done  
6: done  
8: done  
0: done  
4: done  
3: done  
2: done  
5: done  
9: cone  
exit.

---

<div class="post-metadata">

**Author:** ![Masatoshi\_SEKI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@Masatoshi\_SEKI](https://www.ruby-forum.com/u/Masatoshi_SEKI)\
**Post date:** [May 23, 2007, 10:03am UTC](https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444/2 "2007-05-23T10:03:23Z")

</div>

e$B$J$+$@$G$9!#e(B

At Tue, 20 Mar 2007 22:50:05 +0900,  
Masatoshi SEKI wrote in [ruby-dev:30653]:

> e$B=PCY$l$F$7$^$$$^$7$?$,!"$d$C$He(Bsvne$BHG$r;n$7;O$a$^$7$?!#e(B

e$B8+Mn$H$7$F$^$7$?!#e(B

> e$B\<!$N%9%/%j%W%H$N$h$&$Je(BQueuee$B$rBT$C$F$k%9%l%C%I$,$"$k\>uBV$Ge(B  
> e$B%a%$%s%9%l%C%I$,=\*N;$9$k%1!\<%9$Ge(B  
> [BUG] queue 0x424010 freed with live thread(s) waiting  
> e$B$H$J$j$^$7$?!#e(B

r12068e$B$Ge(Bwait\_condvar()e$B$,\>o$Ke(Bmutexe$B$r:F%m%C%/$9$k$h$&$K$J$C$?$;$$e(B  
e$B$N$h$&$G$9!#e(B

# Index: eval.c

— eval.c (revision 12298)  
+++ eval.c (working copy)  
@@ -11214,8 +11214,17 @@ rb\_thread\_wakeup(thread)  
VALUE thread;  
{

- if (!RTEST(rb\_thread\_wakeup\_alive(thread)))
- rb\_raise(rb\_eThreadError, “killed thread”);
- return thread;  
+}
- 

+VALUE  
+rb\_thread\_wakeup\_alive(thread)

- VALUE thread;  
+{  
rb\_thread\_t th = rb\_thread\_check(thread);

- rb\_raise(rb\_eThreadError, “killed thread”);

- return Qnil;  
rb\_thread\_ready(th);

@@ -11292,5 +11301,5 @@ rb\_thread\_kill(thread)

```
 kill_thread(th, 0);

```

- return thread;

- return thread;  
}

@@ -11645,4 +11654,13 @@ rb\_thread\_abort\_exc\_set(thread, val)

+enum rb\_thread\_status  
+rb\_thread\_status(thread)

- VALUE thread;  
+{
- rb\_thread\_t th = rb\_thread\_check(thread);
- return th-\>status;  
+}
- 
- 

/\*

- call-seq:  
@@ -12121,5 +12139,5 @@ rb\_thread\_value(thread)

static VALUE  
-rb\_thread\_status(thread)  
+rb\_thread\_status\_name(thread)  
VALUE thread;  
{  
@@ -12982,5 +13000,5 @@ Init\_Thread()  
rb\_define\_method(rb\_cThread, “exit!”, rb\_thread\_kill\_bang, 0);  
rb\_define\_method(rb\_cThread, “value”, rb\_thread\_value, 0);

- rb\_define\_method(rb\_cThread, “status”, rb\_thread\_status, 0);

- rb\_define\_method(rb\_cThread, “status”, rb\_thread\_status\_name, 0);  
rb\_define\_method(rb\_cThread, “join”, rb\_thread\_join\_m, -1);  
rb\_define\_method(rb\_cThread, “alive?”, rb\_thread\_alive\_p, 0);  
Index: intern.h  
===================================================================  
— intern.h (revision 12298)  
+++ intern.h (working copy)  
@@ -205,6 +205,8 @@ void rb\_thread\_polling \_((void));  
void rb\_thread\_sleep \_((int));  
void rb\_thread\_sleep\_forever \_((void));  
+enum rb\_thread\_status rb\_thread\_status \_((VALUE));  
VALUE rb\_thread\_stop \_((void));  
VALUE rb\_thread\_wakeup \_((VALUE));  
+VALUE rb\_thread\_wakeup\_alive \_((VALUE));  
VALUE rb\_thread\_run \_((VALUE));  
VALUE rb\_thread\_kill \_((VALUE));  
Index: ext/thread/thread.c  
===================================================================  
— ext/thread/thread.c (revision 12298)  
+++ ext/thread/thread.c (working copy)  
@@ -13,4 +13,5 @@  
#include \<intern.h\>  
#include \<rubysig.h\>  
+#include \<node.h\>

static VALUE rb\_cMutex;  
@@ -208,6 +209,5 @@ static VALUE  
wake\_thread(VALUE thread)  
{

- return rb\_rescue2(rb\_thread\_wakeup, thread,
- 

```
 NULL, Qundef, rb_eThreadError, 0);

```

- return rb\_thread\_wakeup\_alive(thread);  
}

@@ -215,6 +215,8 @@ static VALUE  
run\_thread(VALUE thread)  
{

- return rb\_rescue2(rb\_thread\_run, thread,
- 

```
 NULL, Qundef, rb_eThreadError, 0);

```

- thread = wake\_thread(thread);
- if (RTEST(thread) && !rb\_thread\_critical)
- rb\_thread\_schedule();
- return thread;  
}

@@ -226,5 +228,7 @@ wake\_one(List \*list)  
waking = Qnil;  
while (list-\>entries && !RTEST(waking)) {

- 

```
   waking = wake_thread(shift_list(list));

```

- waking = shift\_list(list);
- if (waking == Qundef) break;
- waking = wake\_thread(waking);  
}

@@ -267,8 +271,15 @@ assert\_no\_survivors(List \*waiting, const  
{  
Entry \*entry;

- VALUE ths = 0;
- for (entry = waiting-\>entries; entry; entry = entry-\>next) {

- 

```
   if (RTEST(wake_thread(entry->value))) {

```

- 

```
       rb_bug("%s %p freed with live thread(s) waiting", label, 

```

addr);

- 

```
   }

```

- if (RTEST(wake\_thread(entry-\>value))) {
- 

```
 if (!ths) ths = rb_ary_new();

```

- 

```
 rb_ary_push(ths, entry->value);

```

- }
- }
- if (ths) {
- rb\_bug("%s %p freed with live thread(s) %s waiting",
- 

```
    label, addr, RSTRING_PTR(rb_inspect(ths)));

```

}  
}  
@@ -404,9 +415,14 @@ lock\_mutex(Mutex \*mutex)  
rb\_thread\_critical = 1;

- while (RTEST(mutex-\>owner)) {
- 

```
   wait_list(&mutex->waiting);

```

- 

```
   rb_thread_critical = 1;

```

- if (!RTEST(mutex-\>owner)) {
- mutex-\>owner = current;
- }
- else {
- push\_list(&mutex-\>waiting, current);
- while (mutex-\>owner != current) {
- 

```
 rb_thread_stop();

```

- 

```
 rb_thread_critical = 1;

```

- }  
}

- mutex-\>owner = current;

+static VALUE  
+relock\_mutex(Mutex \*mutex)  
+{

- VALUE current = rb\_thread\_current();
- 
- switch (rb\_thread\_status(current)) {
- 

```
 case THREAD_RUNNABLE:

```

- 

```
 case THREAD_STOPPED:

```

- lock\_mutex(mutex);
- break;
- 

```
 default:

```

- break;
- }
- return Qundef;  
+}
- 

/\*

- Document-method: unlock  
@@ -443,6 +475,6 @@ unlock\_mutex\_inner(Mutex \*mutex)  
}

- mutex-\>owner = Qnil;  
waking = wake\_one(&mutex-\>waiting);

- mutex-\>owner = waking;

- 
- if (waking == Qundef) {
- 

```
   return Qfalse;

```

- if (!RTEST(waking)) {
- return Qfalse;  
}

- if (RTEST(waking)) {
- 

```
   run_thread(waking);

```

- }

- run\_thread(waking);

- if (waking == Qundef) {
- 

```
   return Qnil;

```

- if (waking == Qundef || !RTEST(waking)) {
- return Qnil;  
}

- if (RTEST(waking)) {
- 

```
   run_thread(waking);

```

- }

- run\_thread(waking);

- VALUE waking;

- rb\_thread\_critical = 1;  
if (rb\_thread\_current() != mutex-\>owner) {

- 

```
   rb_thread_critical = 0;

```

- 

```
   rb_raise(rb_eThreadError, "not owner of the synchronization 

```

mutex");

- rb\_thread\_critical = 0;
- rb\_raise(rb\_eThreadError, “not owner of the synchronization mutex”);
- }
- waking = unlock\_mutex\_inner(mutex);
- if (RTEST(waking)) {
- wake\_thread(waking);  
}

- unlock\_mutex\_inner(mutex);
- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, lock\_mutex,  
(VALUE)mutex);

- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, relock\_mutex,  
(VALUE)mutex);  
}

@@ -836,8 +868,8 @@ rb\_queue\_marshal\_load(VALUE self, VALUE  
array = rb\_marshal\_load(data);  
if (TYPE(array) != T\_ARRAY) {

- 

```
   rb_raise(rb_eRuntimeError, "expected Array of queue data");

```

- rb\_raise(rb\_eTypeError, “expected Array of queue data”);  
}  
if (RARRAY(array)-\>len \< 1) {

- 

```
   rb_raise(rb_eRuntimeError, "missing capacity value");

```

- rb\_raise(rb\_eArgError, “missing capacity value”);  
}  
queue-\>capacity = NUM2ULONG(rb\_ary\_shift(array));

---

<div class="post-metadata">

**Author:** ![Masatoshi\_SEKI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@Masatoshi\_SEKI](https://www.ruby-forum.com/u/Masatoshi_SEKI)\
**Post date:** [May 25, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444/3 "2007-05-25T18:45:21Z")

</div>

e$B$J$+$@$G$9!#e(B

At Wed, 23 May 2007 17:02:15 +0900,  
Nobuyoshi N. wrote in [ruby-dev:30809]:

> > e$B\<!$N%9%/%j%W%H$N$h$&$Je(BQueuee$B$rBT$C$F$k%9%l%C%I$,$"$k\>uBV$Ge(B  
> > e$B%a%$%s%9%l%C%I$,=\*N;$9$k%1!\<%9$Ge(B  
> > [BUG] queue 0x424010 freed with live thread(s) waiting  
> > e$B$H$J$j$^$7$?!#e(B
> 
> r12068e$B$Ge(Bwait\_condvar()e$B$,\>o$Ke(Bmutexe$B$r:F%m%C%/$9$k$h$&$K$J$C$?$;$$e(B  
> e$B$N$h$&$G$9!#e(B

[ruby-dev:30809]e$B$G$b!"%m%C%/$7$?$^$^e(Bforke$B$9$k$He(B[BUG]e$B$K$J$j$^$9!#e(B

# Index: eval.c

— eval.c (revision 12390)  
+++ eval.c (working copy)  
@@ -11214,8 +11214,17 @@ rb\_thread\_wakeup(thread)  
VALUE thread;  
{

- if (!RTEST(rb\_thread\_wakeup\_alive(thread)))
- rb\_raise(rb\_eThreadError, “killed thread”);
- return thread;  
+}
- 

+VALUE  
+rb\_thread\_wakeup\_alive(thread)

- VALUE thread;  
+{  
rb\_thread\_t th = rb\_thread\_check(thread);

- rb\_raise(rb\_eThreadError, “killed thread”);

- return Qnil;  
rb\_thread\_ready(th);

@@ -11292,5 +11301,5 @@ rb\_thread\_kill(thread)

```
 kill_thread(th, 0);

```

- return thread;

- return thread;  
}

@@ -11645,4 +11654,13 @@ rb\_thread\_abort\_exc\_set(thread, val)

+enum rb\_thread\_status  
+rb\_thread\_status(thread)

- VALUE thread;  
+{
- rb\_thread\_t th = rb\_thread\_check(thread);
- return th-\>status;  
+}
- 
- 

/\*

- call-seq:  
@@ -12121,5 +12139,5 @@ rb\_thread\_value(thread)

static VALUE  
-rb\_thread\_status(thread)  
+rb\_thread\_status\_name(thread)  
VALUE thread;  
{  
@@ -12148,5 +12166,5 @@ rb\_thread\_status(thread)  
\*/

-static VALUE  
+VALUE  
rb\_thread\_alive\_p(thread)  
VALUE thread;  
@@ -12982,5 +13000,5 @@ Init\_Thread()  
rb\_define\_method(rb\_cThread, “exit!”, rb\_thread\_kill\_bang, 0);  
rb\_define\_method(rb\_cThread, “value”, rb\_thread\_value, 0);

- rb\_define\_method(rb\_cThread, “status”, rb\_thread\_status, 0);

- rb\_define\_method(rb\_cThread, “status”, rb\_thread\_status\_name, 0);  
rb\_define\_method(rb\_cThread, “join”, rb\_thread\_join\_m, -1);  
rb\_define\_method(rb\_cThread, “alive?”, rb\_thread\_alive\_p, 0);  
Index: intern.h  
===================================================================  
— intern.h (revision 12390)  
+++ intern.h (working copy)  
@@ -205,8 +205,11 @@ void rb\_thread\_polling \_((void));  
void rb\_thread\_sleep \_((int));  
void rb\_thread\_sleep\_forever \_((void));  
+enum rb\_thread\_status rb\_thread\_status \_((VALUE));  
VALUE rb\_thread\_stop \_((void));  
VALUE rb\_thread\_wakeup \_((VALUE));  
+VALUE rb\_thread\_wakeup\_alive \_((VALUE));  
VALUE rb\_thread\_run \_((VALUE));  
VALUE rb\_thread\_kill \_((VALUE));  
+VALUE rb\_thread\_alive\_p \_((VALUE));  
VALUE rb\_thread\_create \_((VALUE (_)(ANYARGS), void_));  
void rb\_thread\_interrupt \_((void));  
Index: ext/thread/thread.c  
===================================================================  
— ext/thread/thread.c (revision 12390)  
+++ ext/thread/thread.c (working copy)  
@@ -13,4 +13,5 @@  
#include \<intern.h\>  
#include \<rubysig.h\>  
+#include \<node.h\>

static VALUE rb\_cMutex;  
@@ -208,6 +211,5 @@ static VALUE  
wake\_thread(VALUE thread)  
{

- return rb\_rescue2(rb\_thread\_wakeup, thread,
- 

```
 NULL, Qundef, rb_eThreadError, 0);

```

- return rb\_thread\_wakeup\_alive(thread);  
}

@@ -215,6 +217,8 @@ static VALUE  
run\_thread(VALUE thread)  
{

- return rb\_rescue2(rb\_thread\_run, thread,
- 

```
 NULL, Qundef, rb_eThreadError, 0);

```

- thread = wake\_thread(thread);
- if (RTEST(thread) && !rb\_thread\_critical)
- rb\_thread\_schedule();
- return thread;  
}

@@ -226,5 +230,7 @@ wake\_one(List \*list)  
waking = Qnil;  
while (list-\>entries && !RTEST(waking)) {

- 

```
   waking = wake_thread(shift_list(list));

```

- waking = shift\_list(list);
- if (waking == Qundef) break;
- waking = wake\_thread(waking);  
}

@@ -267,8 +273,15 @@ assert\_no\_survivors(List \*waiting, const  
{  
Entry \*entry;

- VALUE ths = 0;
- for (entry = waiting-\>entries; entry; entry = entry-\>next) {

- 

```
   if (RTEST(wake_thread(entry->value))) {

```

- 

```
       rb_bug("%s %p freed with live thread(s) waiting", label, 

```

addr);

- 

```
   }

```

- if (RTEST(wake\_thread(entry-\>value))) {
- 

```
 if (!ths) ths = rb_ary_new();

```

- 

```
 rb_ary_push(ths, entry->value);

```

- }
- }
- if (ths) {
- rb\_bug("%s %p freed with live thread(s) %s waiting",
- 

```
    label, addr, RSTRING_PTR(rb_inspect(ths)));

```

}  
}  
@@ -304,4 +317,6 @@ typedef struct \_Mutex {  
} Mutex;

+#define MUTEX\_LOCKED\_P(mutex) (RTEST((mutex)-\>owner) &&  
rb\_thread\_alive\_p((mutex)-\>owner))  
+  
static void  
mark\_mutex(Mutex \*mutex)  
@@ -362,5 +377,5 @@ rb\_mutex\_locked\_p(VALUE self)  
Mutex \*mutex;  
Data\_Get\_Struct(self, Mutex, mutex);

- return RTEST(mutex-\>owner) ? Qtrue : Qfalse;

- return MUTEX\_LOCKED\_P(mutex) ? Qtrue : Qfalse;  
}

@@ -381,5 +396,5 @@ rb\_mutex\_try\_lock(VALUE self)  
Data\_Get\_Struct(self, Mutex, mutex);

- if (RTEST(mutex-\>owner))

- if (MUTEX\_LOCKED\_P(mutex))  
return Qfalse;

@@ -404,9 +419,18 @@ lock\_mutex(Mutex \*mutex)  
rb\_thread\_critical = 1;

- while (RTEST(mutex-\>owner)) {
- 

```
   wait_list(&mutex->waiting);

```

- 

```
   rb_thread_critical = 1;

```

- if (!MUTEX\_LOCKED\_P(mutex)) {
- mutex-\>owner = current;
- }
- else {
- push\_list(&mutex-\>waiting, current);
- do {
- 

```
 rb_thread_stop();

```

- 

```
 rb_thread_critical = 1;

```

- 

```
 if (!MUTEX_LOCKED_P(mutex)) {

```

- mutex-\>owner = current;
- break;
- 

```
 }

```

- } while (mutex-\>owner != current);  
}

- mutex-\>owner = current;

+static VALUE  
+relock\_mutex(Mutex \*mutex)  
+{

- VALUE current = rb\_thread\_current();
- 
- switch (rb\_thread\_status(current)) {
- 

```
 case THREAD_RUNNABLE:

```

- 

```
 case THREAD_STOPPED:

```

- lock\_mutex(mutex);
- break;
- 

```
 default:

```

- break;
- }
- return Qundef;  
+}
- 

/\*

- Document-method: unlock  
@@ -435,14 +475,10 @@ unlock\_mutex\_inner(Mutex \*mutex)  
VALUE waking;

- if (!RTEST(mutex-\>owner)) {

- rb\_raise(rb\_eThreadError, “not owner”);

- }

- if (mutex-\>owner != rb\_thread\_current()) {  
rb\_raise(rb\_eThreadError, “not owner”);  
}

- mutex-\>owner = Qnil;  
waking = wake\_one(&mutex-\>waiting);

- mutex-\>owner = waking;

- 
- if (waking == Qundef) {

- if (!RTEST(waking)) {  
return Qfalse;  
}

- if (RTEST(waking)) {
- 

```
   run_thread(waking);

```

- }

- run\_thread(waking);

- if (waking == Qundef) {

- if (waking == Qundef || !RTEST(waking)) {  
return Qnil;  
}

- if (RTEST(waking)) {
- 

```
   run_thread(waking);

```

- }

- run\_thread(waking);

- VALUE waking;

- rb\_thread\_critical = 1;  
if (rb\_thread\_current() != mutex-\>owner) {  
@@ -639,6 +673,9 @@ wait\_condvar(ConditionVariable \*condvar,  
rb\_raise(rb\_eThreadError, “not owner of the synchronization  
mutex”);  
}

- unlock\_mutex\_inner(mutex);
- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, lock\_mutex,  
(VALUE)mutex);

- waking = unlock\_mutex\_inner(mutex);
- if (RTEST(waking)) {
- wake\_thread(waking);
- }
- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, relock\_mutex,  
(VALUE)mutex);  
}

@@ -836,8 +874,8 @@ rb\_queue\_marshal\_load(VALUE self, VALUE  
array = rb\_marshal\_load(data);  
if (TYPE(array) != T\_ARRAY) {

- 

```
   rb_raise(rb_eRuntimeError, "expected Array of queue data");

```

- rb\_raise(rb\_eTypeError, “expected Array of queue data”);  
}  
if (RARRAY(array)-\>len \< 1) {

- 

```
   rb_raise(rb_eRuntimeError, "missing capacity value");

```

- rb\_raise(rb\_eArgError, “missing capacity value”);  
}  
queue-\>capacity = NUM2ULONG(rb\_ary\_shift(array));

---

<div class="post-metadata">

**Author:** ![Masatoshi\_SEKI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@Masatoshi\_SEKI](https://www.ruby-forum.com/u/Masatoshi_SEKI)\
**Post date:** [June 20, 2007, 10:05am UTC](https://www.ruby-forum.com/t/bug-queue-0x424010-freed-with-live-thread-s-waiting/89444/4 "2007-06-20T10:05:45Z")

</div>

e$B$J$+$@$G$9!#e(B

At Sat, 26 May 2007 01:44:25 +0900,  
removed\_email\_address@domain.invalid wrote in [ruby-dev:30822]:

> > > e$B\<!$N%9%/%j%W%H$N$h$&$Je(BQueuee$B$rBT$C$F$k%9%l%C%I$,$"$k\>uBV$Ge(B  
> > > e$B%a%$%s%9%l%C%I$,=\*N;$9$k%1!\<%9$Ge(B  
> > > [BUG] queue 0x424010 freed with live thread(s) waiting  
> > > e$B$H$J$j$^$7$?!#e(B
> > 
> > r12068e$B$Ge(Bwait\_condvar()e$B$,\>o$Ke(Bmutexe$B$r:F%m%C%/$9$k$h$&$K$J$C$?$;$$e(B  
> > e$B$N$h$&$G$9!#e(B
> 
> [ruby-dev:30809]e$B$G$b!"%m%C%/$7$?$^$^e(Bforke$B$9$k$He(B[BUG]e$B$K$J$j$^$9!#e(B

1.8.6-p36e$B$K$Oe(B[ruby-dev:30822]e$B$8$c$J$/$Fe(B[ruby-dev:30809]e$B$,F~$C$Fe(B  
e$B$$$^$9$,!":F8=%F%9%H$O$J$$$b$N$Ne(B[ruby-Bugs-11507]e$B$G%(%i!\<$,5/$-e(B  
e$B$k$H$$$&Js9p$,Mh$F$$$^$9!#e(B

e$B$H$j$"$($:e(Brelock\_mutexe$B$O$?$7$+$K$^$:$=$&$J$N$G0J2\<$N$h$&$J%Q%Ce(B  
e$B%A$r=P$7$F$\_$?$N$G$9$,!“e(B[ruby-dev:30653]e$B$KBP$9$k1F6A$,$h$/$o$+e(B  
e$B$j$^$;$s!#:F8=$9$k$O$:$H;W$C$?$N$G$9$,!”\<j85$G$O$J$\<$+5/$-$^$;e(B  
e$B$s$G$7$?!#$I$J$?$+3NG’$G$-$k$G$7$g$&$+!#e(B

# Index: ext/thread/thread.c

## — ext/thread/thread.c (revision 12567) +++ ext/thread/thread.c (working copy) @@ -13,7 +13,4 @@ #include \<intern.h\> #include \<rubysig.h\> -#include \<node.h\>

-enum rb\_thread\_status rb\_thread\_status \_((VALUE));

static VALUE rb\_cMutex;  
@@ -263,8 +260,8 @@ wait\_list\_cleanup(List \*list)  
}

-static void  
+static VALUE  
wait\_list(List \*list)  
{

- rb\_ensure(wait\_list\_inner, (VALUE)list, wait\_list\_cleanup,  
(VALUE)list);

- return rb\_ensure(wait\_list\_inner, (VALUE)list, wait\_list\_cleanup,  
(VALUE)list);  
}

@@ -447,20 +444,4 @@ rb\_mutex\_lock(VALUE self)  
}

-static VALUE  
-relock\_mutex(Mutex \*mutex)  
-{

- VALUE current = rb\_thread\_current();
- 
- switch (rb\_thread\_status(current)) {
- 

```
 case THREAD_RUNNABLE:

```

- 

```
 case THREAD_STOPPED:

```

- lock\_mutex(mutex);
- break;
- 

```
 default:

```

- break;
- }
- return Qundef;  
-}
- 

/\*

- Document-method: unlock  
@@ -676,5 +657,5 @@ wait\_condvar(ConditionVariable \*condvar,  
wake\_thread(waking);  
}

- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, relock\_mutex,  
(VALUE)mutex);

- rb\_ensure(wait\_list, (VALUE)&condvar-\>waiting, lock\_mutex,  
(VALUE)mutex);  
}
