2 ms·
> If I'm dealing with atomics and concurrent code I really want to tell the compiler, hey, inline constants maybe, but don't reorder or combine operations. If
by josephcsible 5y ago
> If I'm dealing with atomics and concurrent code I really want to tell the compiler, hey, inline constants maybe, but don't reorder or combine operations.
If that's what you want, then declare your variables volatile (in addition to being atomic, not instead).
- overgard 5y agoAt this point I wouldn't expect the compiler to care.
- astrange 5y agoYou probably want seq_cst atomics. That's easier to understand and control then volatile is.
- josephcsible 5y agoseq_cst doesn't forbid optimizing `x = 1; x = 2;` into `x = 2;`, though, but volatile does.
- jcelerier 5y agoThat doesn't mean that your CPU isn't gonna optimize it anyways afterwards, see for instance all the macro-fusion cases described in here : https://en.wikichip.org/wiki/macro-operation_fusion https://en.wikichip.org/wiki/macro-operation_fusion
- astrange 5y agoAtomic instructions wouldn’t be reordered like that on a CPU, that’s the point of using them. Non-atomic ones might be, and volatile would since it’s only a C concept. Although it wouldn’t be through instruction fusion, more like non-coherent caches.