It looks like the examples are broken.<p><pre><code>  uint32_t fetch_multiply(std::atomic&lt;uint32_t&gt;&amp; shared, uint32_t multiplier)
  {
      uint32_t oldValue = shared.load();
      while (!shared.compare_exchange_weak(oldValue, oldValue * multiplier))
      {
      }
      return oldValue;
  }

</code></pre>
If shared.compare_exchange_weak() fails because of a concurrent writer, then the while loop will never exit (unless another writer sets the value of shared to oldValue).<p>What the author wants is something like this:<p><pre><code>  uint32_t fetch_multiply(std::atomic&lt;uint32_t&gt;&amp; shared, uint32_t multiplier)
  {
      while(1) {
          uint32_t oldValue = shared.load();
          if(shared.compare_exchange_weak(oldValue, oldValue * multiplier)) {
              return oldValue;
          }
      }
  }
</code></pre>
The other examples have the same problem.