From: "ara.t.howard" Date: 2008-04-16T13:10:44+09:00 Subject: Re: Parallel for loop On Apr 15, 2008, at 9:35 PM, Fredrik wrote: > But there isn't, right? cfp:~ > cat a.rb module Enumerable def forkify &b map do |*a| r, w = IO.pipe fork do r.close w.write( Marshal.dump( b.call(*a) ) ) end [ w.close, r ].last end.map{|r| Marshal.load [ r.read, r.close ].first} end end result = [0, 1, 2, 3].forkify do |i| p [ Process.ppid, Process.pid ] i ** 2 end p result cfp:~ > ruby a.rb [80870, 80871] [80870, 80872] [80870, 80873] [80870, 80874] [0, 1, 4, 9] a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama