From: samuel@... Date: 2017-03-27T21:05:27+00:00 Subject: [ruby-core:80411] [Ruby trunk Bug#7097] Thread locals don't work inside Enumerator Issue #7097 has been updated by ioquatix (Samuel Williams). I feel like the solution that was reached here is confusing. I feel like the correct outcome would have been Thread#[] and Thread#[]= are what thread_variable_set and thread_variable_get do. Fiber#[] and Fiber#[]= are what Thread#[] and Thread#[]= do. Otherwise, when Fiber is used internally, unexpected behaviour may result. It may even be that certain operations optionally use a Fiber or not, and if that happens, it's even more confusing/unspecified. Does it make sense to continue this discussion, or are we done, and that's simply how it is? ---------------------------------------- Bug #7097: Thread locals don't work inside Enumerator https://bugs.ruby-lang.org/issues/7097#change-63905 * Author: tenderlovemaking (Aaron Patterson) * Status: Closed * Priority: Normal * Assignee: ko1 (Koichi Sasada) * Target version: 2.0.0 * ruby -v: ruby 2.0.0dev (2012-09-25 trunk 37032) [x86_64-darwin12.2.0] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- I set a thread local outside an Enumerator. The Enumerator runs inside the same thread where I set the local. I would expect the thread local to be available since I am in the same thread, but it is not. Here is a test that shows the problem: require 'minitest/autorun' class ThreadLocalBreaks < MiniTest::Unit::TestCase def test_thread_local_in_enumerator Thread.current[:foo] = "bar" thread, value = Enumerator.new { |y| y << [Thread.current, Thread.current[:foo]] }.next assert_equal Thread.current, thread # passes assert_equal Thread.current[:foo], value # fails end end ---Files-------------------------------- thread_locals.patch (2.68 KB) thread_variables.patch (8.62 KB) thread_variables.patch (9.43 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: