When linking the above code I get linker error LNK2019 : unresolved external symbol _InterlockedAnd referenced in function g_atomic_int_and. The same error occurs for InterlockedOr and InterlockedXor. However, all the others are fine.
All the others seem to be in kernel32.dll - but InterlockedAnd, InterlockedOr and InterlockedXor are nowhere to be found. It looks like the intention was for them to get inlined but I can't seem to make it work. What am I doing wrong...
"A problem well stated is a problem half solved.” - Charles F. Kettering
This simple test case won't even compile, let alone link:-
Code:
#include <windows.h>
int main (int argc, char *argv[])
{
LONG x=0, y=2, z=3;
x = InterlockedExchangeAdd (&y, z);
x = InterlockedAnd (&y, 4);
return 0;
}
HelloWorld.cpp(12) : error C3861: 'InterlockedAnd': identifier not found
However, it builds perfectly if I comment out the call to InterlockedAnd(). Would somebody be kind enough to try this in VC9 or 10? I think I've concluded that it must be a bug in VC8.
"A problem well stated is a problem half solved.” - Charles F. Kettering
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. For the Intel Itanium-based systems and x64 architectures, this function is implemented using the compiler intrinsic. For the x86 architecture, use the _InterlockedAnd compiler intrinsic directly.
Bookmarks