How does x86 pause instruction work in spinlock *and* can it be used in other scenarios?

前端 未结 4 988
不思量自难忘°
不思量自难忘° 2020-12-01 02:35

The pause instruction is commonly used in the loop of testing spinlock, when some other thread owns the spinlock, to mitigate the tight loop. It\'s said that it

4条回答
  •  -上瘾入骨i
    2020-12-01 03:12

    A processor suffers a severe performance penalty when exiting the loop because it detects a possible memory order violation. The PAUSE instruction provides a hint to the processor that the code sequence is a spin-wait loop. The processor uses this hint to avoid the memory order violation in most situations, which greatly improves processor performance. For this reason, it is recommended that a PAUSE instruction be placed in all spin-wait loops. An additional function of the PAUSE instruction is to reduce the power consumed by Intel processors.

    [source: Intel manual]

提交回复
热议问题