Quantcast
Channel: Atomic swap in C - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Atomic swap in C

$
0
0

I think I'm missing something obvious here. I have code like this:

int *a = <some_address>;int *b = <another_address>;// ...// desired atomic swap of addresses a and b hereint *tmp = a;a = b; b = tmp;

I want to do this atomically. I've been looking at __c11_atomic_exchange and on OSX the OSAtomic methods, but nothing seems to perform a straight swap atomically. They can all write a value into 1 of the 2 variables atomically, but never both.

Any ideas?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>