Issue #5750 has been updated by Julien A.


Although I consider this behavior (and the reason why it was done) completely absurd, how about at least changing the documentation to mention the real behavior of the supposedly thread-local storage ?
Replacing thread-local by fiber-local in the description of Thread[] and Thread[]= makes a lot more sense for me since every thread has its own root fiber, by reading the current documentation I expect my second call to Thread.current[:a] to return 1 not nil which is clearly misleading and could create nice bugs...

The current text is ( for Thread[sym] ):

Attribute Referenceˇ˝Returns the value of a thread-local variable, using either a symbol or a string name. If the specified variable does not exist, returns nil.

----------------------------------------
Bug #5750: Thread.current local-variables behavior
http://redmine.ruby-lang.org/issues/5750

Author: Julien A
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: 1.9.3-p0


Hi, I stumbled upon something which for me is a bug and wanted to check if it is working as intended or not:

    Thread.current[:a] = 1
    p Thread.current[:a] # => 1

    Fiber.new do
     p Thread.current[:a] # => nil
    end.resume


There is clearly a problem in either the documentation or the implementation for me there, we are in the same thread yet the returned values are different which is completely counter intuitive...
Why not add a fiber-variables store to allow the following and keep things separated between fibers and threads

    Fiber.current[:a] = 1
    p Fiber.current[:a] # => 1

    Fiber.new do
     p Fiber.current[:a] # => nil
    end.resume

Which is now the behavior I would expect.




-- 
http://redmine.ruby-lang.org