<div dir="ltr">What's the best way to get atomic/CAS instructions in C/C++, while keeping your code as portable as possible?<br><div class="gmail_quote"><div dir="ltr"><div><br></div><div>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, <a href="http://www.hpl.hp.com/research/linux/atomic_ops/" target="_blank">http://www.hpl.hp.com/research/linux/atomic_ops/</a>, but it seems too heavyweight.</div>
<div><br></div><div>I can use C++11, but (1) not good for C (2) still not as widespread as C++ is.</div><div><br></div><div>A way which is also compatible with windows, is a big plus.</div><div><br></div><div>PS,</div><div>
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.</div></div>
</div><br></div>