views:

29

answers:

2

I know that on MacOSX / PosiX systems, there is atomic-compare-and-swap for C/C++ code via g++.

However, I don't need the compare -- I just want to atomically swap two values. Is there an atomic swap operation available? [Everythign I can find is atomic_compare_and_swap ... and I just want to do the swap, without comparing].

Thanks!

+2  A: 

Hi, the "lock xchg" intel assembly instruction probably achieves what you want but i dont think there is a GCC wrapper function to make it portable. Therefor your stuck using inline assembly(not portable) or using compare and swap and forcing the compare to be true(inneficient). Hope this helps :-)