Hello all,

I just tried the example from page 118 of "Programming Ruby". It doesn't
print the expected result (a delta > 0), but instead hangs after printing
"counter started", so probably the counter thread is getting all the
processor time. Is this expected behaviour (that is, did the threading
implementation change after the book was out), or is something wrong with my
version of Ruby? I am using the stable snapshot from 2001-05-02 on QNX RTP.

Thanks for your help

Roland


(Slightly modified) code from pickaxe book:


count1 = count2 = 0
delta = 0

counter = Thread.new do
  puts "counter started"
  loop do
    count1 += 1
    count2 += 1
  end
end

spy = Thread.new do
  puts "spy started"
  loop do
    delta += (count2 - count1).abs
  end
end

puts "main started"
sleep 1
Thread.critical = 1

puts count1
puts count2
puts delta