Calling Thread.join blocks the current (main) thread. However not calling join results in all spawned threads to be killed when the main thread exits. How does one spawn per
You need to join the threads outside of the loop.
for i in 1..100 do
puts "Creating thread #{i}"
t = Thread.new(i) do |mi|
sleep 1
puts "Thread #{mi} done"
end
end
# Wait for all threads to end
Thread.list.each do |t|
# Wait for the thread to finish if it isn't this thread (i.e. the main thread).
t.join if t != Thread.current
end