From: ts Date: 2002-03-28T23:17:10+09:00 Subject: Re: Threads in Iterators >>>>> "N" == Norman Makoto Su writes: N> My concern is if there is a chance that two yields will happen at the same time N> and mess things up (vals will be corrupted). Is this possible? It depend what you call corrupted pigeon% cat b.rb #!/usr/bin/ruby arr = [1,2,3,4] def arr.each 0.upto(length-1) do |i| Thread.new(self[i]) {|val| sleep(rand .1) yield val } end end vals = [] val = nil arr.each {|val| vals << val sleep(rand .1) vals << (val + 10) } Thread.list.each do |aThread| aThread.join if aThread != Thread.current end puts vals pigeon% pigeon% b.rb 4 14 3 1 11 2 12 12 pigeon% pigeon% b.rb 2 1 3 13 13 13 4 14 pigeon% Guy Decoux