2 ms·
Relaxed atomics translate to native loads and stores. In theory there is no cost to them apart from the compiler barrier which prevents other loads/stores from
by eloff 6y ago
Relaxed atomics translate to native loads and stores. In theory there is no cost to them apart from the compiler barrier which prevents other loads/stores from moving past them, depending on the case.
For larger objects, std::atomic uses a mutex, so it's kind of silly anyway. If you wanted a mutex, better to make it explicit.
- mehrdadn 6y ago> Relaxed atomics translate to native loads and stores Native loads and stores with lock... and that is on x86. https://gcc.godbolt.org/z/asKna4 https://gcc.godbolt.org/z/asKna4 Definitely not the same as a native operation. > In theory there is no cost to them This isn't theory though. > apart from the compiler barrier which prevents other loads/stores from moving past them, depending on the case Why apart from? Why not include this obvious deficiency? It's a legitimate objection and a pretty important component to my point you can't just brush aside out of inconvenience. > For larger objects, std::atomic uses a mutex, so it's kind of silly anyway. If you wanted a mutex, better to make it explicit. Better in your eyes. Clearly not in the standard writers', or they wouldn't have introduced the functionality. My only point is if people do decide to use it (the reasons not being the subject of this debate), they come across this shortcoming.