From: "Iñaki Baz Castillo" Date: 2008-04-19T03:51:38+09:00 Subject: Re: Parallel for loop El Viernes, 18 de Abril de 2008, Fredrik escribió: > def forkmap(n = nil) >     nproc = 0 >     result = map do |*a| >       r, w = IO.pipe >       fork do >         r.close >         w.write( Marshal.dump( yield(*a) ) ) >       end >       if n and (nproc+=1) >= n >         Process.wait ; nproc -= 1 >       end >       [ w.close, r ].last >     end >     Process.waitall >     result.map{|r| Marshal.load [ r.read, r.close ].first} >   end > > > irb> Benchmark.realtime {[1,2,3].forkmap{|i| sleep 1 } } > => 1.01688504219055 > irb> Benchmark.realtime {[1,2,3].forkmap(1){|i| sleep 1 } } > => 3.01162004470825 It's simply great :) -- Iñaki Baz Castillo