From: Erik Veenstra Date: 2008-04-19T03:20:47+09:00 Subject: Re: forkoff - parallel processing for ruby enumerables Just a word of warning: The construction "Thread.new(i){|i|" is useless, by definition. Just like "i=i" is useless too. If i isn't defined outside the loop, you don't have to pas i to the thread, so "Thread.new{" will do. However, if i is defined outside the loop (which it isn't, in your code...), "Thread.new(i){|i|" won't work (see below): It's better to use "Thread.new(i1){|i2|" instead. gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- a = (1..10).to_a a1 = a.map{|i| Thread.new { sleep 0.01 ; i }}.map{|t| t.value} a2 = a.map{|i| Thread.new(i) {|i| sleep 0.01 ; i }}.map{|t| t.value} # Will do. i = nil a3 = a.map{|i| Thread.new(i) {|i| sleep 0.01 ; i }}.map{|t| t.value} # Won't do! a4 = a.map{|i1| Thread.new(i1){|i2|sleep 0.01 ; i2}}.map{|t| t.value} p a1 # ==> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] p a2 # ==> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] p a3 # ==> [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] p a4 # ==> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ----------------------------------------------------------------