tags:

views:

60

answers:

3

What is the best cross platform library to use for atomic compare and swap operations in c++?

...Or at least for amd64 on Linux and Windows?

+1  A: 

Try using boost. It offers a lot of support for atomic operations.

PeterK
Probably my own blindness, but I checked boost and I couldn't support for a CAS operation that would work on 64 bit datatypes. Any chance you can show me what you mean?
James P Michels III
A: 

It depends on the compiler compatibility you need.

If you are using GCC on both platforms, you can just use GCC's atomic primitives, as they are tied to the hardware architecture, not the OS platform.

Otherwise, as PeterK suggested, look at Boost. There is a Boost.Atomic candidate library; I don't know what its status on being incorporated is.

Michael E
I am using __sync_val_compare_and_swap now. I just assumed that this relatively common functionality would have a widely used standard library for it.
James P Michels III
+1  A: 

An alternative to boost is TBB (Threading Building Blocks). It is not a large scale lib like boost and focuses on parallel programming.

jdehaan