A definitive answer to the Interlocked code generation questions

Mark Lacey, a developer who works on the compilers and related tools, has a great blog post up with a definitive explanation of the Interlocked* code generation issue that I mentioned before. He left a comment linking to his post, but I thought I’d link it from the main page since I did complain about this issue on the main page.

I’ll let you read Mark’s detailed explanation of the bug in question, but at a high level, he says that the following functions are affected:

  • _InterlockedAnd()
  • _InterlockedOr()
  • _InterlockedXor()

He also suggests a couple of workarounds for code that needs to check return values from these functions.

Note that although he refers to the visual studio compilers, the issue is present in the currently released DDK compilers (13.10) from the 3790 series. It does seem to be resolved by the WDK’s 14.00 compiler (although the WDK is still in beta, of course).

I continue to be impressed with how responsive Microsoft’s bloggers are to the communities they support. I had really only expected a don’t do this KB article in a few months. Getting an authoritative developer response like this is fantastic. And, from the look of the first dozen or so posts, it looks like Mark’s blog is going to be great. Added to the blogroll!

One Response to “A definitive answer to the Interlocked code generation questions”

  1. Alexandre Grigoriev says:

    This bug is still present in x86 and x64 compilers in WDK 6001 CTP.

Leave a Reply