# Thread local variables

**URL:** <https://www.ruby-forum.com/t/thread-local-variables/97768>\
**Category:** Ruby\
**Created:** [January 26, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/thread-local-variables/97768 "2006-01-26T21:27:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![russellf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@russellf](https://www.ruby-forum.com/u/russellf)\
**Post date:** [January 26, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/thread-local-variables/97768/1 "2006-01-26T21:27:20Z")

</div>

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
