Is the assignment equivalent to loading / storing for std :: atomic <bool>
I see that this potentially answered the question Should I explicitly name the atomic load / storage? .
So, for the sake of clarity, I will summarize my question in the hope that future readers will find this clear.
Is an
std::atomic<bool> b(false);
bool x = b;
Same as
std::atomic<bool> b(false);
bool x = b.load();
AND
std::atomic<bool> b(false);
b = true;
Same as
std::atomic<bool> b(false);
b.store(true);
If this is true, then:
- Why are there 2 options? What are the obvious benefits?
- Is it good to use atomics to prefer a more detailed load () / store () over a potentially confusing assignment (=), which can mean either depending on whether the LHS or RHS is an atom.
NOTE I already know that both variables cannot be std :: atomic ie LHS and RHS, since it is impossible to read and write atomically in the same instruction.
+4
1