Permalink
Browse files

Register finalizer thread instance variables.

  • Loading branch information...
1 parent c1dde8e commit 9ff72871f8726ffae5a2b3b45aa16106a8cbdcf3 @kstephens committed Apr 12, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/asir/thread_variable.rb
@@ -121,7 +121,7 @@ def #{name}= __val
thread_attrs[:'#{name}'] = [ __val ]
end
END
- $stderr.puts "expr::\n#{expr}\n====" if opts[:debug]
+ $stderr.puts "expr::\n#{expr}\n====" if opts[:debug] || DEBUG
class_eval *expr
end
end
@@ -130,11 +130,19 @@ def attr_getter_thread *names
opts = Hash === names[-1] ? names.pop : EMPTY_HASH
expr = [ <<"END", __FILE__, __LINE__ ]
+def self.attr_thread_hash(obj)
+ thr = Thread.current
+ ObjectSpace.define_finalizer(obj) do | oid |
+ (thr[:'#{self.name}\#'] ||= { }).delete(oid)
+ end
+ { }
+end
+
def thread_attrs
- (Thread.current[:'#{self.name}\#'] ||= { })[self.object_id] ||= { }
+ (Thread.current[:'#{self.name}\#'] ||= { })[self.object_id] ||= #{self.name}.attr_thread_hash(self)
end
-def attr_thread_forget! oic = self.object_id
+def attr_thread_clear_all! oid = self.object_id
(Thread.current[:'#{self.name}\#'] ||= { }).delete(oid)
end
END

0 comments on commit 9ff7287

Please sign in to comment.