Best practice for using CAS/atomic semantics in C/C++

Best practice for using CAS/atomic semantics in C/C++

Elazar Leibovich elazarl at gmail.com
Sun Oct 21 01:39:41 IST 2012


What's the best way to get atomic/CAS instructions in C/C++, while keeping
your code as portable as possible?

Unfortunately, the best looking solution so far looks like depending on
GCC's intrinsics, (since it's so widespread), but it doesn't sound right.
There's also a project from HP,
http://www.hpl.hp.com/research/linux/atomic_ops/, but it seems too
heavyweight.

I can use C++11, but (1) not good for C (2) still not as widespread as C++
is.

A way which is also compatible with windows, is a big plus.

PS,
The natural place for this looks like the pthread standard. Probably this
sort of thing weren't that popular back then when the standard was written.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20121021/27b992a3/attachment.html>


More information about the Linux-il mailing list