Why this simple program give no output, and terminates immidiatly
after its launched? There should be thread running and giving lots of
‘lala’, am I right?
class Bar
def initialize
end
def foo
Thread.new do
while true
puts “lala\n”
end
end
end
end
Why this simple program give no output, and terminates immidiatly
after its launched? There should be thread running and giving lots of
‘lala’, am I right?
class Bar
def initialize
end
def foo
Thread.new do
try changing this to a = Thread.new
while true
puts "lala\n"
end
end
then add an a.join here
end
end
b=Bar.new
b.foo
Someone else would have to explain why that happens. Don’t know enough
about threads (let alone ruby’s) to explain that.
Hi Pawel, here is one example, see if you can follow it.
class Bar
def initialize( msg ) @msg = msg
end
def foo
t_exit = Time.now.to_i + 3
while true
puts @msg
break if Time.now.to_i > t_exit
sleep 0.5
end
end
end