不是吧。
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也是不能保证原子性的。
参考 http://blogs.msdn.com/b/oldnewthing/archive/2013/09/13/10448736.aspx
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.