4

Based on the Microsoft documentation InterlockedCompareExchange64 is not available as a Windows API call until Windows Vista. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683562(v=vs.85).aspx.

However, it seems like the _InterlockedCompareExchange64 compiler intrinsic might be available on Windows XP as long as you are using a Pentium or above processor: http://msdn.microsoft.com/en-us/library/ttk2z1ws(VS.80).aspx .

Is this correct? Is there any gotcha there?

  • `CMPXCHG8B` has been available since Pentium, so the compiler should have no problem implementing the intrinsic – harold Oct 03 '11 at 14:14
  • Just as an addum: InterlockedOr will implicitly include InterlockedCompareExchange64, so if you want your program to run on WinXP, also substitute it with _InterlockedOr (happend to me when I tried to compile Screened Poisson Surface Reconstruction ( PoissonRecon32.exe ) for WinXP in VS2010) – Oliver Zendel Feb 19 '13 at 16:02
  • @OliverZendel - how did you substitute _InterlockedOr exactly? I'm having the same problem and the intrinsic takes different parameters to the function call. – Joris Timmermans Apr 18 '13 at 09:17
  • Hi, I changed InterlockedOr( (volatile unsigned long long*)&(int) , int); to _InterlockedOr( (volatile long *)&(int) , int); which worked in my case. Your mileage may vary ;) – Oliver Zendel May 17 '13 at 11:43

1 Answers1

3

The documentation is quite consistent. API function is available since Vista or Server 2003, but if you prefer an intrinsic (that is no extrernal API required) MS compiler will implement the function through specific CPU instruction (see Remarks):

Because _InterlockedCompareExchange64 uses the cmpxchg8b instruction, it is not available on pre-Pentium processors, such as the 486.

It is noted that this instruction might be an issue with very old CPUs. This means that if you run your app on 486 processor, it will just crash as soon as it stumbles on this code.

Roman R.
  • 68,205
  • 6
  • 94
  • 158