Skip to content

Instantly share code, notes, and snippets.

@careo
Last active January 3, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save careo/8426590 to your computer and use it in GitHub Desktop.
Save careo/8426590 to your computer and use it in GitHub Desktop.
thread-fiber-locals
RUBY_DESCRIPTION
# => "ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.0.0]"
Thread.current[:some_local] # => nil
Thread.current[:some_local] = 'main' # => "main"
Thread.current[:some_local] # => "main"
f1 = Fiber.new do
Thread.current[:some_local] # => nil
Thread.current[:some_local] = 'f1' # => "f1"
Thread.current[:some_local] # => "f1"
end
f2 = Fiber.new do
Thread.current[:some_local] # => nil
Thread.current[:some_local] = 'f1' # => "f1"
Thread.current[:some_local] # => "f1"
end
Thread.current[:some_local] # => "main"
f1.resume
f2.resume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment