A
ara.t.howard
can anyone see issues with this:
harp:~ > cat a.rb
class Thread
class << self
alias_method "__new__", "new"
def new *a, &b
parent = Thread.current
__new__(*a) do |*a|
Thread.current.parent = parent
b.call *a
end
end
end
def parent
self['parent']
end
def parent= parent
self['parent'] = parent
end
def ancestors
list = [t = self]
while((t = t.parent))
list << t
end
list
end
end
Thread.new{ Thread.new{ Thread.new{ sleep 2; p Thread.current.ancestors } } }
STDIN.gets
harp:~ > ruby a.rb
[#<Thread:0xb75d2264 run>, #<Thread:0xb75d2354 dead>, #<Thread:0xb75d2444 dead>, #<Thread:0xb75df900 sleep>]
it's hard to wrap my head around, but even GC seems like it'd be fine - the
child, upon death, will allow the parent to be freed, and so on.
-a
harp:~ > cat a.rb
class Thread
class << self
alias_method "__new__", "new"
def new *a, &b
parent = Thread.current
__new__(*a) do |*a|
Thread.current.parent = parent
b.call *a
end
end
end
def parent
self['parent']
end
def parent= parent
self['parent'] = parent
end
def ancestors
list = [t = self]
while((t = t.parent))
list << t
end
list
end
end
Thread.new{ Thread.new{ Thread.new{ sleep 2; p Thread.current.ancestors } } }
STDIN.gets
harp:~ > ruby a.rb
[#<Thread:0xb75d2264 run>, #<Thread:0xb75d2354 dead>, #<Thread:0xb75d2444 dead>, #<Thread:0xb75df900 sleep>]
it's hard to wrap my head around, but even GC seems like it'd be fine - the
child, upon death, will allow the parent to be freed, and so on.
-a