From: 7stud -- Date: 2008-02-21T11:55:31+09:00 Subject: Re: trouble with threads gm gm wrote: > I am trying to expand my web crawler to use multiple threads (with > mechanize), and I ma having some trouble. It seems that each thread is > not creating a local variable, but rather they are sharing the "index" > variable threads = [] 10.times do |i| threads[i] = Thread.new(i) do |index| if index == 0 index += 100 end puts index end end threads.each do |t| t.join end --output:-- 100 1 2 3 4 5 6 7 8 9 If the threads shared the index variable, then each line of the output would be 100. Instead, i gets assigned to index for each thread, and nothing a thread does to its index variable has any effect on another thread's index variable. -- Posted via http://www.ruby-forum.com/.