Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-12-12T20:26:24ZRuby Issue Tracking System
Redmine Ruby master - Bug #5750 (Closed): Thread.current local-variables behaviorhttps://bugs.ruby-lang.org/issues/57502011-12-12T20:26:24Zschmurfy (Julien A)schmurfy@gmail.com
<p>Hi, I stumbled upon something which for me is a bug and wanted to check if it is working as intended or not:</p>
<pre><code>Thread.current[:a] = 1
p Thread.current[:a] # => 1
Fiber.new do
p Thread.current[:a] # => nil
end.resume
</code></pre>
<p>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...<br>
Why not add a fiber-variables store to allow the following and keep things separated between fibers and threads</p>
<pre><code>Fiber.current[:a] = 1
p Fiber.current[:a] # => 1
Fiber.new do
p Fiber.current[:a] # => nil
end.resume
</code></pre>
<p>Which is now the behavior I would expect.</p>