title: How does x86 pause instruction work in spinlock *and* can it be used in other scenarios?
body: <p>The <code>pause</code> instruction is commonly used in the loop of testing <a href="http://en.wikipedia.org/wiki/Spinlock" rel="noreferrer">spinlock</a>, when some other thread owns the spinlock, to mitigate the tight loop. It's said that it is equivalent to some NOP instructions. Could somebody tell me how exactly it works for spinlock optimization? It seems to me that even the NOP instructions are a waste of CPU time. Will they decrease CPU usage?</p>
  <p>Another question is that could I use pause instruction for other similar purposes. For example, I have a busy thread which keeps scanning some places (e.g. a queue) to retrieve new nodes; however, sometimes the queue is empty and the thread is just wasting cpu time. Sleep the thread and wake it up by other threads may be an option, however the thread is critical, so I don't want to make it sleep.</p>
  <p>Could pause instruction work for my purpose to mitigate the CPU usage? Currently it uses 100% cpu of a physical core?</p>