How does x86 pause instruction work in spinlock *and* can it be used in other scenarios?
pause instruction is commonly used in the loop of testing [spinlock][1], 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?

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 justing 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. Could pause instruction work for my purpose to mitigate the CPU usage? Currently it uses 100% cpu of a physical core?

Thanks.


  [1]: http://en.wikipedia.org/wiki/Spinlock
How does x86 pause instruction work in spinlock *and* can it be used in other scenarios?
===

pause instruction is commonly used in the loop of testing [spinlock][1], 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?

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 justing 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. Could pause instruction work for my purpose to mitigate the CPU usage? Currently it uses 100% cpu of a physical core?

Thanks.


  [1]: http://en.wikipedia.org/wiki/Spinlock