Skip to content

Commit

Permalink
Changed ObjectSpace.define_finalizer call to be ruby 1.9.2 compatible…
Browse files Browse the repository at this point in the history
…. There should probably be a Ruby

version test to make it compatible with both 1.8 and 1.9. Had to update spec to call GC.start to
get it to pass on Mac - didn't need it on Linux.
  • Loading branch information
Scott Persinger committed May 20, 2011
1 parent f4fd003 commit 3bdd55f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tlattr_accessors.rb
Expand Up @@ -35,7 +35,7 @@ def #{name}=(val)
#{ivar} = Hash.new #{'{|h, k| h[k] = val}' if first_is_default} unless #{ivar}
thread_id = Thread.current.object_id
unless #{ivar}.has_key?(thread_id)
ObjectSpace.define_finalizer(Thread.current, lambda { #{ivar}.delete(thread_id) })
ObjectSpace.define_finalizer(Thread.current, proc {|id| #{ivar}.delete(thread_id) })
end
#{ivar}[thread_id] = val
end
Expand Down
1 change: 1 addition & 0 deletions spec/thread_local_accessors_spec.rb
Expand Up @@ -69,6 +69,7 @@ def initialize(value)
x.bar = Bar.new(rand)
end.join
end
GC.start
hash = x.send :instance_variable_get, '@_tlattr_bar'
hash.size.should < (n / 2) # it should be a lot lower than n!
end
Expand Down

0 comments on commit 3bdd55f

Please sign in to comment.