Project

General

Profile

Backport #725 ยป test.rb

The code producing the error - cenobyte (Sebastian Morawietz), 11/08/2008 10:40 PM

 
#!/usr/bin/env ruby


require 'thread'

class MyTest
@@ids={}
@@ids.instance_variable_set("@mutex", Mutex.new)
def @@ids.synchronize
@mutex.synchronize do
yield
end
end
def self.finalize(object_id)
@@ids.synchronize do
@@ids.delete(object_id)
end
end
def initialize
ObjectSpace.define_finalizer(self, self.class.method(:finalize))
@@ids.synchronize do
@@ids[object_id]="blah"
end
end
end

def doit
100000.times do
MyTest.new
end
end

10.times do
Thread.new do
doit
end
end
    (1-1/1)