From: eregontp@... Date: 2020-01-06T18:22:12+00:00 Subject: [ruby-core:96693] [Ruby master Feature#8215] Support accessing Fiber-locals and backtraces for a Fiber Issue #8215 has been updated by Eregon (Benoit Daloze). `Fiber#[]` and `Fiber#[]=` sounds fine, but what if somebody does: `some_fiber = Fiber.new { ... }; Thread.new { some_fiber[:fiber_local] }`? I think that should raise or not be possible. If it would return the value, it would imply synchronization on every access to fiber locals which seems unfortunate. By making the API `Fiber.[]`, we can avoid that entirely and have true fiber-locals, which can only be accessed by that Fiber: ```ruby Fiber[:my_fiber_local] = 42 value = Fiber[:my_fiber_local] # no way to access fiber locals of another Fiber ``` I think for new APIs we should take the chance to make them only possible to use correctly. We could even finally have Fiber and Thread local in a consistent way: ```ruby # access Fiber-local Fiber[:my_fiber_local] # access Thread-local Thread[:my_thread_local] ``` ---------------------------------------- Feature #8215: Support accessing Fiber-locals and backtraces for a Fiber https://bugs.ruby-lang.org/issues/8215#change-83678 * Author: halorgium (Tim Carey-Smith) * Status: Assigned * Priority: Normal * Assignee: ioquatix (Samuel Williams) * Target version: ---------------------------------------- =begin 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: ((<"github/rubinius/rubinius/2200"|URL:https://github.com/rubinius/rubinius/issues/2200>)) =end ---Files-------------------------------- 0001-cont.c-fiber-local-accessors.patch (2.94 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: