# ThreadGroup and Ruby 1.9

**URL:** <https://www.ruby-forum.com/t/threadgroup-and-ruby-1-9/121577>\
**Category:** Ruby\
**Created:** [November 29, 2007, 1:37am UTC](https://www.ruby-forum.com/t/threadgroup-and-ruby-1-9/121577 "2007-11-29T01:37:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [November 29, 2007, 1:37am UTC](https://www.ruby-forum.com/t/threadgroup-and-ruby-1-9/121577/1 "2007-11-29T01:37:38Z")

</div>

Just wondering if this is a bug in 1.9 or intended behavior …

$ cat a.rb

tg = ThreadGroup.new  
t = Thread.new {  
sleep 3600  
}  
tg.add t

puts “tg = #{tg.list.inspect}”  
puts “default = #{ThreadGroup::Default.list.inspect}”

sleep 0.1  
tg.add t

puts “tg = #{tg.list.inspect}”  
puts “default = #{ThreadGroup::Default.list.inspect}”

Now we run this little script in Ruby 1.8 and get the following output  
…

$ ruby a.rb  
tg = [#\<Thread:0x28eec sleep\>]  
default = [#\<Thread:0x35700 run\>]  
tg = [#\<Thread:0x28eec sleep\>]  
default = [#\<Thread:0x35700 run\>]

Our thread group contains one thread, and the default thread group  
contains one thread – all is happy. Now we run this little script in  
Ruby 1.9 and get the following output …

$ /usr/local/ruby1.9/bin/ruby a.rb  
tg = []  
default = [#\<Thread:0x311794 run\>, #\<Thread:0x307654 sleep\>]  
tg = [#\<Thread:0x307654 sleep\>]  
default = [#\<Thread:0x311794 run\>]

It appears that the first call to ThreadGroup#add fails. The second  
call works because the thread “t” has actually been started by the  
ruby interpreter – this happened when we called sleep.

Any thoughts on this one?

Blessings,  
TwP
