Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.