title: Where is the correct location to use lock
body: <p>I try to find the best similarity in multithreaded environment.</p>
  
  <p>Is there any better alternative or both versions are same below?</p>
  
  <pre><code> // float bestSimilarity is shared
   // float _similarity is local
  
   lock(locker) 
       if (_similarity &gt; bestSimilarity)
           bestSimilarity = _similarity;
  </code></pre>
  
  <p>vs</p>
  
  <pre><code> if (_similarity &gt; bestSimilarity)
       lock(locker) 
           bestSimilarity = _similarity;
  </code></pre>