Issue #8215 has been updated by Eregon (Benoit Daloze).

Category set to core
Status changed from Open to Closed

Thread#[] and friends access *Fiber*-local variables, as the doc says:

(Attribute Reference---Returns the value of a fiber-local variable (current
thread's root fiber if not explicitely inside a Fiber), using either a symbol
or a string name.)

This is unfortunate, as indeed one might expect it to be *thread*-local,
but it has been made fiber-local for safety.

In ruby >= 2.0.0, you have thread_variable_{get,set} and such for manipulating *thread*-local variables.
Not as nice, but at least the API is there. See #7097.
----------------------------------------
Feature #8215: Support accessing Fiber-locals and backtraces for a Fiber
https://bugs.ruby-lang.org/issues/8215#change-38215

Author: halorgium (Tim Carey-Smith)
Status: Closed
Priority: Normal
Assignee: 
Category: core
Target version: 


As part of debugging celluloid, I have been wanting to diagnose where the Fibers are running and their various locals.

I would expect the following to work.

Thread.current[:key] = "outside"
fiber = Fiber.new do
  Thread.current[:key] = "inside"
  Fiber.yield
end
fiber.resume
fiber[:key] == "inside" # true
fiber.backtrace # ...

I also wonder whether Fiber#[] should be implemented, so Fiber.current[:key] is possible.

For reference, here is the issue on the rubinius issue tracker: https://github.com/rubinius/rubinius/issues/2200


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