Thread local variables

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

ti = getThreadIndex()
threads[ti] = thread(line) { |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

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)


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs