xs = [] threads = [] def mkthread(f) Thread.new do (0...500).each do |i| xs << f(i) end end end threads << mkthread(-> (i) { 2 * i }) threads << mkthread(-> (i) { 2 * i + 1 }) threads.each(&:join) puts xs.join("\n")