Forum: Ruby thread local variables

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Russell F. (Guest)
on 2006-01-26 22:27
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 topic is locked and can not be replied to.