Code:
threads = [] Thread.abort_on_exception=true begin # throw exceptions in threads so we can see them threads << Thread.new{@a = MyClass.m1} threads << Thread.new{@b = MyClass.m2} threads << Thread.new{@c = MyClass.m3} threads.each { |thr| thr.join } rescue Exception => e puts "EXCEPTION: #{e.inspect}" puts "MESSAGE: #{e.message}" end
Crash:
.rvm/gems/ ruby-2.1.3@req /gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:in load_missing_constant': Circular dependency detected while autoloading constant MyClass
After a short search, it seems that since each thread references MyClass, it causes an error during manual startup. If I add a single line with a link to MyClass before I call Thread, it seems to prevent the error.
My question is, is there a βrightβ way to prevent this, or is it some kind of ruby ββerror? I understand that startup was thread safe, for http://blog.plataformatec.com.br/2012/08/eager-loading-for-greater-good/
source share