title: Volatile vs. Interlocked vs. lock
body: <p>Let's say that a class has a <code>public int counter</code> field that is accessed by multiple threads. This <code>int</code> is only incremented or decremented.</p>
  
  <p>To increment this field, which approach should be used, and why?</p>
  
  <ul>
  <li><code>lock(this.locker) this.counter++;</code>,</li>
  <li><code>Interlocked.Increment(ref this.counter);</code>,</li>
  <li>Change the access modifier of <code>counter</code> to <code>public volatile</code>.</li>
  </ul>
  
  <p>Now that I've discovered <code>volatile</code>, I've been removing many <code>lock</code> statements and the use of <code>Interlocked</code>. But is there a reason not to do this?</p>