by rrss · 7y ago · 0 comments
My understanding is that compilers can always assume that there is no other thread involved, which (part of) why C11 atomics are necessary. Is that not the case?
void foo(const int* const p1, int* const p2) {
int a = *p1;
*p2 += 42;
int b = *p1;
return a == b; // b = a + 42
}
int main() {
int x = 0;
return foo(&x, &x);
}It is allowed to concurrently read from const regions. But not concurrently read and write, and definitely not concurrently write.