ThreadGroup and Ruby 1.9

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