Skip to content

Instantly share code, notes, and snippets.

@nahi
Created December 22, 2010 05:18
Show Gist options
  • Save nahi/751125 to your computer and use it in GitHub Desktop.
Save nahi/751125 to your computer and use it in GitHub Desktop.
require 'singleton'
loop do
classes = []
1000.times do
classes << Class.new do
include Singleton
end
end
(0..10).map do
Thread.new do
classes.each do |cls|
cls.instance
end
end
end.map(&:join)
puts "loop completed"
end
% ruby -v singleton_killer.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
loop completed
singleton_killer.rb:18: undefined method `instance' for #<Class:0x1001896a0> (NoMethodError)
from singleton_killer.rb:1:in `join'
from singleton_killer.rb:1:in `to_proc'
from singleton_killer.rb:21:in `map'
from singleton_killer.rb:21
from singleton_killer.rb:5:in `loop'
from singleton_killer.rb:5
% ruby -v singleton_killer.rb
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
loop completed
loop completed
loop completed
loop completed
singleton_killer.rb:18: undefined method `instance' for #<Class:0x100348c70> (NoMethodError)
from singleton_killer.rb:1:in `join'
from singleton_killer.rb:1:in `to_proc'
from singleton_killer.rb:21:in `map'
from singleton_killer.rb:21
from singleton_killer.rb:5:in `loop'
from singleton_killer.rb:5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment