Thread local variables

Hi Folk,
         I have a program that creates threads in a loop like so:

file.each{|line|
  ti = getThreadIndex()
  threads[ti] = thread(line) { |line|

    do_stuff(line)
  }

}

It appears from my observation that the value passed to do_stuff is
*not* local to the thread. Instead it is what ever the current line is
in the outer loop. If I change { |line| to {linex then it works
properly.

getThreadInded selects an unused thread from the array.

Is this as intended? If so I find it very confusing!

BTW I'm running ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
(as shipped by Apple)

Russell

···

--
Posted via http://www.ruby-forum.com/.