title: Determine if concurrency logic can be done using *only* CAS operations
body: <p>For high-performance multi-threading system, is there a deterministic way/methodology to determine what concurrency logic can be done using <em>only</em> compare-and-swap a.k.a. atomic operations, what must use locks, semophones and/or barriers?</p>
  
  <p>My systems always involve a lot of concurrency and multi-threading issue. Some are simple as one can work out if a simple lock is needed quickly; but for some complicated problems, or trials to push performance to extreme, I found that I don't have a consistent deterministic methodology to tell if a problem can be resolved using only CAS. As an example:</p>
  
  <ol>
  <li><p>Typical producer/consumer model. Concurrent queue can resolve the problem using CAS only.</p></li>
  <li><p>Producer/consumer model with a lot of updates but conflated consumption. In this case if double-buffering is used, read/write lock must apply; however, if we use triple-buffering, then using CAS is essentially possible.</p></li>
  </ol>
  
  <p>Roughly speaking, we could say <em>if a piece of logic can be separated into several inter-dependent states, each need only CAS, then such logic can be resolved by only CAS.</em> But applying this in real problems seems much more complicated, and I do feel lack of a good methodology to divided and determine if such logic division is possible.</p>
  
  <p>Please kindly share me your experiences or any methodologies I am not aware of.</p>