Quantcast
Channel: Mutexes, atomic and fences : what offers the best tradeoff and portability ? C++11 - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Thomas McGuire for Mutexes, atomic and fences : what offers the best tradeoff and portability ? C++11

$
0
0

Yep, X86 and ARM have different memory models.The C++11 memory model is however not platform-specific, it has the same behavior everywhere.

That means implementation of the C++11 atomics is different on each platform - on x86, which has a fairly strong memory model, the implementation of std::atomic might get away without special assembler instructions when storing a value, while on ARM, the implementation needs special locking or fence instructions internally.

So you can simply use the atomic classes in C++11, they will work the same on all platforms. If you want to, you can even tweak the memory order if you are absolutely sure what you are doing. A weaker memory order might be faster since the implementation of the atomics might need less assembler instructions for locks and fences internally.

I can highly recommend watching Herb Sutter's talk Atomic Weapons for some detailed explanations about this.


Viewing all articles
Browse latest Browse all 3

Trending Articles



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