When spinning on an atomic operation, you should add some kind of yield operation. The &quot;pause&quot; instruction in x86 at least. On newer CPUs a &quot;monitor&quot; and &quot;mwait&quot; can work a little better (but may not be available in user space). Do not use thread_yield or other kernel calls, because at that point you&#x27;re better off using a mutex.<p>When spinning on atomics, the interconnect between cores needs to do a lot of work synchronizing the memory. When adding a pause or monitor instruction, the core will give an opportunity for the other hyperthread in the same core to execute, reducing the amount of churn on the interconnect.<p>Counterintuitively, adding a &quot;pause&quot; in the spin loop will make the program faster by yielding the CPU core for a few nanoseconds.