On a multicore x86, is a LOCK necessary as a prefix to XCHG?

前端 未结 3 1794
轮回少年
轮回少年 2020-12-13 20:06

If mem is a shared memory location, do I need:

XCHG EAX,mem

or:

LOCK XCHG EAX,mem

to do the

3条回答
  •  醉酒成梦
    2020-12-13 20:37

    As per the 80386 Instruction Manual, BUS LOCK is asserted for the duration of the exchange. The LOCK prefix has no precedence for this operation and neither does the value of the I/O Privilege Level.

    My suggestion is that since the documentation states that BUS LOCK is asserted regardless of the presence of the LOCK prefix, LOCK XCHG EAX, mem is otherwise safe. When in doubt, add a LOCK.

提交回复
热议问题