-
-
Save osak/71648a7360d9a0a34f57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
require 'monitor' | |
log = [] | |
END { | |
log << "end" | |
puts log | |
} | |
m = Monitor.new | |
h = Set.new | |
f = ->(objid){ | |
begin | |
m.synchronize do | |
log << "delete #{objid.to_s(16)}" | |
h.delete(objid) | |
end | |
rescue Exception => e | |
log << e.to_s | |
end | |
} | |
loop do | |
a = Array.new(10000000) | |
ObjectSpace.define_finalizer(a, &f) | |
m.synchronize do | |
if h.include?(a.object_id) | |
raise "#{a.object_id.to_s(16)} already included!" | |
end | |
h << a.object_id | |
log << "insert #{a.object_id.to_s(16)}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUKI.N@aincrad> ruby a.rb | |
insert b1394c | |
insert b27f78 | |
can't be called from trap context | |
insert b27f00 | |
can't be called from trap context | |
insert 919b64 | |
can't be called from trap context | |
insert a21f34 | |
can't be called from trap context | |
insert a21e6c | |
can't be called from trap context | |
insert b27eb0 | |
insert b27dfc | |
can't be called from trap context | |
can't be called from trap context | |
insert b27d98 | |
can't be called from trap context | |
insert 91977c | |
can't be called from trap context | |
insert a21fac | |
can't be called from trap context | |
insert a21e08 | |
can't be called from trap context | |
end | |
a.rb:26:in `block (2 levels) in <main>': b27eb0 already included! (RuntimeError) | |
from /usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' | |
from a.rb:24:in `block in <main>' | |
from a.rb:21:in `loop' | |
from a.rb:21:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment