title: Implement a C++ lock using atomic instructions?
body: <p>I saw a question on a website the other day and at first I thought the answer was trivial, but then I thought it wasnt.</p>
  
  <p>How do you implement a lock using atomic instructions? Compare and swap is the standard way of atomically checking the value of something, but it is intended to be for lock-free designs, hence my bewilderment.... </p>