何时应使用Win32 InterlockedExchange函数? [英] When should the Win32 InterlockedExchange function be used?

查看:90
本文介绍了何时应使用Win32 InterlockedExchange函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 InterlockedExchange ,我想知道何时应该使用此功能.我认为,在x86处理器上设置32位值应该总是原子的吗?
在我要使用该函数的情况下,新值不取决于旧值(它不是增量操作). 您能否提供一个示例,说明该方法是强制性的(我不是在寻找InterlockedCompareExchange)

I came across the function InterlockedExchange and was wondering when I should use this function. In my opinion, setting a 32 Bit value on an x86 processor should always be atomic?
In the case where I want to use the function, the new value does not depend on the old value (it is not an increment operation). Could you provide an example where this method is mandatory (I'm not looking for InterlockedCompareExchange)

推荐答案

在多处理器或多核计算机中,每个核都有其自己的缓存-因此,每个核都有各自对内容内容的不同看法.系统内存是

In a multi-processor or multi-core machine each core has it's own cache - so each core has each own potentially different "view" of what the content of the system memory is.

线程同步机制负责内核之间的同步,有关更多信息,请参见

Thread synchronization mechanisms take care of synchronizing between cores, for more information look at http://blogs.msdn.com/oldnewthing/archive/2008/10/03/8969397.aspx or google for acquire and release semantics

这篇关于何时应使用Win32 InterlockedExchange函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆