Following up from Multiple assignment in one line, I would be curious to know how that would work for atomic data types, in particular with an example with boolean type.
Given:
class foo {
std::atomic<bool> a;
std::atomic<bool> b;
public:
void reset();
[...] //Other methods that might change a and b
}
Is there any difference between:
void foo::reset() {
a = false;
b = false;
}
And:
void foo::reset() {
a = b = false;
}
Namely, in the second case, can it happen that after b
is assigned false
, another thread set b
to true
before b
is read to assign its value to a
, so that at the end of the instruction the value of a
is true
?
(This would also imply that the latter version is seemingly less efficient)