- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
InterlockedCompareExchangeRelease()
和 InterlockedCompareExchangeAcquire()
之间有什么区别?
当我尝试学习WIN32 API的同步函数时,我发现有两个函数名称不同,但似乎做同样的事情:
LONG __cdecl InterlockedCompareExchangeRelease(
__inout LONG volatile *Destination,
__in LONG Exchange,
__in LONG Comparand
);
和
LONG __cdecl InterlockedCompareExchangeAcquire(
__inout LONG volatile *Destination,
__in LONG Exchange,
__in LONG Comparand
);
我查了一下MSDN,它说这些功能是:
Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 32-bit values and exchanges with another 32-bit value based on the outcome of the comparison.
但是对于InterlockedCompareExchangeAcquire()
,
The operation is performed with acquire memory access semantics.
对于InterlockedCompareExchangeRelease()
,
The exchange is performed with release memory access semantics.
所以我很好奇这两个函数之间的区别。何时使用获取内存访问语义或释放内存访问语义?有没有例子?
谢谢!
最佳答案
普通版本使用完整屏障,而后缀版本仅处理加载或存储,这在某些 CPU(基于 Itanium 的处理器等)上可能会更快
MSDN 有一篇关于 Acquire and Release Semantics 的文章和 Interlocked* API以及this great blog post 。 Linux memory barrier documentation可能也有用...
关于winapi - InterlockedCompareExchange Release() 和 Acquire() 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9764181/
我无法理解 MSDN 文档对 Interlocked Variable Access 的含义函数族。我用 InterlockedExchange用于设置和 InterlockedCompareExch
我正在尝试使用 c++( native )为 64 位处理器运行 android 应用程序,当我执行这些函数时,我遇到了崩溃问题(总线错误) // returns the resulting
我不能在这里使用 C++11 原子 我对使用 InterlockedCompareExchange() 来“原子地”读取变量有疑问。 我问了一个关于这个的问题here ,但我在那里做的是不同的。 “e
假设架构是 ARM64 或 x86-64。 我想确定这两个是否等价: a = _InterlockedCompareExchange64((__int64*)p, 0, 0); MyBarrier()
我正在尝试使用互锁操作使以下代码片段无锁,知道如何翻译吗? if (m_Ref == 0xFFFF) m_Ref = 1; else { if (++m_Ref == 1)
我已经使用 InterlockedExchange 编写了一个基本的自旋锁(见下文)。然而,我已经看到很多实现都使用 InterlockedCompareExchange。我的方法是否以某种不可预见的
InterlockedCompareExchangeRelease() 和 InterlockedCompareExchangeAcquire() 之间有什么区别? 当我尝试学习WIN32 API的同
我在 Windows 10(64 位)上安装了 64 位 Lazarus 1.6/FPC 3.0,并移植了包含 InterlockedCompareExchangePointer 函数的 Delphi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 6 年前。
Microsoft 提供 InterlockedCompareExchange用于执行原子比较和交换操作的函数。还有一个_InterlockedCompareExchange 内在。 在 x86 上,
我在一台装有 mingw64 和所有相关软件包的 fedora 19 x86_64 计算机上。我当时在做一个个人的 c++ 项目,我决定让它成为线程安全的,所以我决定尝试一下 Boost.thread
我是一名优秀的程序员,十分优秀!