Interlocked.CompareExchange(double,double,double) 在 32 位操作系统中工作吗?
我正在维护一个可以由多个线程操作的高性能类。许多字段都是易失性整型,事实证明我需要将其中一个字段升级为双精度型。我很好奇是否有一种无锁的方法可以做到这一点,并且想知道 Interlocked.CompareExchange(double, double, double)
在 32 位操作系统上是否如宣传的那样工作,或者被撕裂读到有问题。
I'm maintaining a high performance class that can be operated on by multiple threads. Many of the fields are volatile ints, and as it turns out I need to upgrade one of those to a double. I'm curious if there is a lock free way to do this, and was wondering if the Interlocked.CompareExchange(double, double, double)
works as advertised on a 32-bit OS, or are torn reads a problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此页面详细介绍了“native “ 联锁功能。它提到了以下限制
因为 _InterlockedCompareExchange64 使用 cmpxchg8b 指令,所以它在 Pentium 之前的处理器上不可用,例如 486。
因此我们可以预期它可用并且也实现为互锁指令操作(而不是使用全锁来模拟)。
This page details the intrinsics of the "native" Interlocked functions. It mentions the following limitations
Because _InterlockedCompareExchange64 uses the cmpxchg8b instruction, it is not available on pre-Pentium processors, such as the 486.
So we can expect that it is available and also implemented as an interlocked instruction operation (rather than being simulated by using a full lock).
是的,它的工作原理与 32 位上的描述相同。这就是
互锁
方法是有的。Yes, it works as described on 32-bit. That's what the
Interlocked
methods are there for.是的,这是有效的。
它使用 InterlockedCompareExchange64 - 如果您想查看 x86 asm 中的可能实现,请查看此处 - http://qc.embarcadero.com/wc/qcmain.aspx?d=6212。
Yes, it's works.
It uses InterlockedCompareExchange64 - if you want to have a look at a possible implementation in x86 asm, have a look here - http://qc.embarcadero.com/wc/qcmain.aspx?d=6212.