R
Ruby Newbee
Hello,
Just copied the code piece from the ruby cookbook:
require 'thread'
class CounterThread < Thread
def initialize
@count = 0
@continue = true
super do
@count += 1 while @continue
puts "I counted up to #{@count} before I was cruelly stopped."
end
end
def stop
@continue = false
end
end
counter = CounterThread.new
sleep 2
counter.stop
After I run it, I didn's see any output, even the expected puts:
"I counted up to #{@count} before I was cruelly stopped."
Where is wrong?
Thanks.
Just copied the code piece from the ruby cookbook:
require 'thread'
class CounterThread < Thread
def initialize
@count = 0
@continue = true
super do
@count += 1 while @continue
puts "I counted up to #{@count} before I was cruelly stopped."
end
end
def stop
@continue = false
end
end
counter = CounterThread.new
sleep 2
counter.stop
After I run it, I didn's see any output, even the expected puts:
"I counted up to #{@count} before I was cruelly stopped."
Where is wrong?
Thanks.