不是吧。
intel文档这么写的
Causes the processor’s LOCK# signal to be asserted during execution of the accompanying instruction (turns the
instruction into an atomic instruction). In a multiprocessor environment, the LOCK# signal ensures that the
processor has exclusive use of any sharedmemory while the signal is asserted.
刚有时间,查了下资料,x86/64上支持LOCK#,看起来应该是可以保证线程安全的,但我不太确定,至于其它CPU上怎么实现更是不清楚,msdn提到“This function is atomic with respect to calls to other interlocked functions.”,如果别人不调用interlocked函数估计windows也是不能保证原子性的。
参考 7c3K9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8X3u0D9L8$3N6K6i4K6u0W2L8i4y4V1L8W2)9J5k6h3y4G2L8g2)9J5c8X3u0Q4x3V1k6G2L8r3c8F1k6i4N6@1K9r3W2F1k6#2)9J5c8X3q4J5j5$3S2A6N6X3g2Q4x3V1j5J5x3o6p5K6i4K6u0r3x3o6W2Q4x3V1j5I4x3#2)9J5c8U0p5H3y4o6b7^5y4K6x3$3i4K6u0W2j5i4y4H3P5l9`.`.
The interlocked functions provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads. This function is atomic with respect to calls to other interlocked functions.
This function is implemented using a compiler intrinsic where possible. For more information, see the WinBase.h header file and _InterlockedExchange.
This function generates a full memory barrier (or fence) to ensure that memory operations are completed in order.
Itanium-based systems: For performance-critical applications, use InterlockedExchangeAcquire instead.
Note This function is supported on Windows RT-based systems.