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?
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.
Try using boost. It offers a lot of support for atomic operations.
An alternative to boost is TBB (Threading Building Blocks). It is not a large scale lib like boost and focuses on parallel programming.
C++0X will [finally] be addressing the issue. For GCC, see http://gcc.gnu.org/wiki/Atomic/GCCMM/ExecutiveSummary and http://gcc.gnu.org/wiki/Atomic/GCCMM/DataRaces.
精彩评论