Issue #7097 has been reported by tenderlovemaking (Aaron Patterson).

----------------------------------------
Bug #7097: Thread locals don't work inside Enumerator
https://bugs.ruby-lang.org/issues/7097

Author: tenderlovemaking (Aaron Patterson)
Status: Open
Priority: Normal
Assignee: 
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/