ThreadGroup and Ruby 1.9

T

Tim Pease

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top