From: "kosaki (Motohiro KOSAKI)" Date: 2012-10-02T03:05:17+09:00 Subject: [ruby-core:47791] [ruby-trunk - Bug #7097][Assigned] Thread locals don't work inside Enumerator Issue #7097 has been updated by kosaki (Motohiro KOSAKI). Status changed from Open to Assigned Assignee set to ko1 (Koichi Sasada) I guess it's a side effect to use Fiber in Enumerator internal. ko1: what do you think? ---------------------------------------- Bug #7097: Thread locals don't work inside Enumerator https://bugs.ruby-lang.org/issues/7097#change-29915 Author: tenderlovemaking (Aaron Patterson) Status: Assigned Priority: Normal Assignee: ko1 (Koichi Sasada) Category: Target version: ruby -v: ruby 2.0.0dev (2012-09-25 trunk 37032) [x86_64-darwin12.2.0] 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 -- http://bugs.ruby-lang.org/