threads = []10.times do thread = Thread.new do 10.times { |i| print i; $stdout.flush; sleep rand(2) } end threads << threadendthreads.each { |thread| thread.join }