summaryrefslogtreecommitdiff
path: root/lib/weakref.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/weakref.rb')
-rw-r--r--lib/weakref.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 9e510d6..459f69f 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -45,7 +45,13 @@ class WeakRef<Delegator
@__id = orig.__id__
ObjectSpace.define_finalizer orig, @@final
ObjectSpace.define_finalizer self, @@final
- ID_MAP[@__id] = [] unless ID_MAP[@__id]
+ __old_status = Thread.critical
+ begin
+ Thread.critical = true
+ ID_MAP[@__id] = [] unless ID_MAP[@__id]
+ ensure
+ Thread.critical = __old_status
+ end
ID_MAP[@__id].push self.__id__
ID_REV_MAP[self.id] = @__id
end