I have been reading through and coding up examples from Anthony Williams' book Concurrency in Practice and needed to enable double-word-compare-and-exchange for gcc4.8 using -mcx16
so that a struct containing a pointer an int could be manipulated in a lock-free atomic manner.
Does Clang (any version) support double-word-compare-and-exchange on x64?
The following code gives linking errors in GCC4.8 and Clang 3.3 without extra compiler options:
#include <atomic>
#include <thread>
struct ReferenceCountedPointer
{
int referenceCount;
void* data;
};
int main()
{
std::atomic<ReferenceCountedPointer> arcp;
ReferenceCountedPointer rcp;
arcp.compare_exchange_weak(rcp, rcp);
return 0;
}
The above program is pointless but illustrates the linking errors I see.
Compilation commands I used for Clang and GCC are:
Clang 3.3:
clang++-mp-3.3 -std=c++11 -stdlib=libc++ CX16.cpp -o CX16
Fails with:
Undefined symbols for architecture x86_64:
"___atomic_compare_exchange", referenced from:
_main in CX16-plVSvq.o
ld: symbol(s) not found for architecture x86_64
GCC4.8:
g++-mp-4.8 -std=c++11 CX16.cpp -o CX16
Fails with:
Undefined symbols for architecture x86_64:
"___atomic_compare_exchange_16", referenced from:
std::atomic<ReferenceCountedPointer>::compare_exchange_weak(ReferenceCountedPointer&, ReferenceCountedPointer, std::memory_order, std::memory_order) in ccOjp95s.o
ld: symbol(s) not found for architecture x86_64