Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment