Skip to content

Instantly share code, notes, and snippets.

@spraints
Created December 5, 2008 14:37
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 spraints/32346 to your computer and use it in GitHub Desktop.
Save spraints/32346 to your computer and use it in GitHub Desktop.
def set(x)
Thread.current[:x] = x
end
def say
puts "#{Thread.current.object_id} #{Thread.current[:x].inspect}"
end
set 'ok'
say
Thread.new do
say
set 't1'
say
end.join
class ContextCopyingThread < Thread
def initialize
self[:x] = Thread.current[:x].dup
super
end
end
t2 = ContextCopyingThread.new do
say
set 't2'
say
end
puts 'waiting...'
t2.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment