On MSDN, I see that
InterlockedCompareExchange64
requires parameters to be 64 aligned,
but for
_InterlockedCompareExchange64
I see no such requirement for alignment, and it is mentioned to provide compiler intrinsic support for the InterlockedCompareExchange64.
So, does this means I can use _InterlockedCompareExchange64 without caring about alignment? 'Cause I don't quite know what alignment means here.
I'm pretty certain that is a documentation mistake, rather than any direct difference between the two function - seeing as they result in exactly the same CMPXCHG8B instruction. [Assuming of course you are looking for it it to actually be atomic on an SMP system - but it's a pretty specialized instruction, so I doubt it has much other use].
It is implied, the _underscore version is only available when _M_IA64 or _M_AMD64 is defined. In other words, when you target your program to a 64-bit processor.
You should use the non-underscore version in your code. When you target a 32-bit processor then the function is implemented in Windows and you'll get a safe version that works with a misaligned destination. But if you target a 64-bit processor then you'll automatically get the _underscore version and the intrinsic. Macro soup in WinBase.h takes care of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With