title: How can I do thread safe singleton with Rails, how keep my classes variables safe?
body: <p>I have read <a href="https://stackoverflow.com/questions/1025432/is-rails-shared-nothing-or-can-separate-requests-access-the-same-runtime-variabl">Is Rails shared-nothing or can separate requests access the same runtime variables?</a> and they explain my problem:</p>
  
  <p>class variable are maybe share between two request to my rails srver, but where is the solution!?</p>
  
  <p>How can I implement a safe singleton between request?</p>
  
  <pre><code>class Foo
    @@instances = []
  end
  </code></pre>
  
  <p>How can I be sure instances will be reset for each request HTTP?!</p>
  
  <p>EDIT: </p>
  
  <p>I find "config.reload_classes_only_on_change = false" solution but i'm not sure it's the best for performance.<br>
  What are the consequences to this option?</p>
  
  <p>I have an exemple to test safe classes variables :</p>
  
  <pre><code>class Test
     def self.log
        @test ||= false
        puts @test
        @test = true
     end
  end
  
  
  class ApplicationController &lt; ActionController::Base
     def index
        Test.log
        Test.log
     end
  end
  </code></pre>
  
  <p>if I start this code with reloading action (F5), I want to read "false" each time in log of rails server. But, by default it's "false" only the first time.</p>
  
  <p>EDIT 2: 
  In fact this option reload class, but not resolve the concurency problem in thread.
  Classes variables are reset but they can be modify by other thread.</p>
  
  <p><strong>How threadsafe classes variables?</strong></p>