title: How to implement "exponential backoff" in this simple mutex implementation?
body: <p>My mutex implementation simply retries on CAS failure (pseudo code):</p>
  
  <pre><code>while(!compare_and_swap(&amp;mutex, 0, 1));
  </code></pre>
  
  <p>But it wastes too many CPU cycles.</p>
  
  <p>I learned that "exponential backoff" improves overall performance. How to implement the backoff delay in C?</p>
  
  <ul>
  <li>Is there a precise timer API (to implement backoff delay)?</li>
  <li>Does OS offer any facility to implement backoff?</li>
  </ul>