# Thread-local variables in Fibers

**URL:** <https://www.ruby-forum.com/t/thread-local-variables-in-fibers/179988>\
**Category:** Ruby\
**Created:** [December 9, 2009, 9:43am UTC](https://www.ruby-forum.com/t/thread-local-variables-in-fibers/179988 "2009-12-09T09:43:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![larsch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ad7895/32.png) [@larsch](https://www.ruby-forum.com/u/larsch)\
**Post date:** [December 9, 2009, 9:43am UTC](https://www.ruby-forum.com/t/thread-local-variables-in-fibers/179988/1 "2009-12-09T09:43:07Z")

</div>

I stumbled on an oddity with thread variables in fibers. I wonder if  
this behaviour is intended and documented:

irb(main):001:0\> Thread.current[:name] = “My name”  
=\> “My name”  
irb(main):002:0\> Fiber.new { Thread.current[:name] }.resume  
=\> nil

Even though, Thread.current is the same in a fiber as in the thread  
invoking Fiber#resume.

irb(main):003:0\> Fiber.new { Thread.current }.resume == Thread.current  
=\> true

Can anyone shed some light? I couldn’t find any information in the  
documentation.

ruby -v : ruby 1.9.1p243 (2009-07-16 revision 24175)

---

<div class="post-metadata">

**Author:** ![larsch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ad7895/32.png) [@larsch](https://www.ruby-forum.com/u/larsch)\
**Post date:** [December 9, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/thread-local-variables-in-fibers/179988/2 "2009-12-09T21:10:49Z")

</div>

> Even though, Thread.current is the same in a fiber as in the thread  
> invoking Fiber#resume.
> 
> irb(main):003:0\> Fiber.new { Thread.current }.resume == Thread.current  
> =\> true
> 
> Can anyone shed some light? I couldn’t find any information in the  
> documentation.

There was some discussion on this in core. I can’t remember if there  
was consensus or not, but one person suggested it may be “intended” so  
that you don’t accidentally have fibers cross-using Thread.current[] for  
their store, which wouldn’t be fiber specific.  
-r
