gpt4 book ai didi

multithreading - 在多核 x86 上,是否需要将 LOCK 作为 XCHG 的前缀?

转载 作者:行者123 更新时间:2023-12-03 02:15:26 25 4
gpt4 key购买 nike

如果 mem 是共享内存位置,我是否需要:

XCHG EAX,mem

或者:

LOCK XCHG EAX,mem

以原子方式进行交换?

谷歌搜索会得到"is"和“否”的答案。有谁明确知道这一点吗?

最佳答案

英特尔的文档似乎很清楚它是多余的。

IA-32 英特尔® 架构软件开发人员手册第 3A 卷:系统编程指南,第 1 部分

7.1.2.1 说:

The operations on which the processor automatically follows the LOCK semantics are as follows:

  • When executing an XCHG instruction that references memory.

同样,

英特尔® 64 和 IA-32 架构软件开发人员手册第 2B 卷:指令集引用,N-Z

XCHG:

If a memory operand is referenced, the processor’s locking protocol is automatically implemented for the duration of the exchange operation, regardless of the presence or absence of the LOCK prefix or of the value of the IOPL.

请注意,这实际上并不意味着无论是否使用 LOCK 前缀,都会断言 LOCK# 信号,7.1.4 描述了如果内存位置被缓存,则在后续处理器上如何在没有 LOCK# 的情况下保留锁定语义。聪明,绝对超出我的想象。

关于multithreading - 在多核 x86 上,是否需要将 LOCK 作为 XCHG 的前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3144335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com