Project

General

Profile

Actions

Bug #7097

closed

Thread locals don't work inside Enumerator

Added by tenderlovemaking (Aaron Patterson) about 12 years ago. Updated over 7 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-09-25 trunk 37032) [x86_64-darwin12.2.0]
[ruby-core:47790]

Description

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_locals.patch tenderlovemaking (Aaron Patterson), 10/03/2012 03:47 AM
thread_variables.patch (8.62 KB) thread_variables.patch tenderlovemaking (Aaron Patterson), 10/26/2012 07:19 AM
thread_variables.patch (9.43 KB) thread_variables.patch tenderlovemaking (Aaron Patterson), 10/27/2012 02:40 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0