Threads and loops

E

Emil Sandin

Hi, if I run this script:

loop{
puts "hello"
sleep 1
}

It outputs "hello" every second.
But if I place it in a separate thread:

Thread.new do
loop{
puts "hello"
sleep 1
}
end



it prints it only one time and then exits.
Why is that?
 
L

Lionel Bouton

Emil Sandin wrote the following on 16.08.2007 13:20 :
[...]
Thread.new do
loop{
puts "hello"
sleep 1
}
end



it prints it only one time and then exits.
Why is that?

You don't wait for the Thread to stop to exit your program.
 

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
474,266
Messages
2,571,318
Members
48,002
Latest member
EttaPfeffe

Latest Threads

Top