Thread-local variables in Fibers

  • Thread starter Lars Christensen
  • Start date
L

Lars Christensen

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)
 
R

Roger Pack

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top