|
|
|
|
|
by aorav
3070 days ago
|
|
The low-level nature of C++ (and also C) makes data races unavoidably undefined behavior. Imagine a data race that causes a torn write on a pointer. This pointer could now point pretty much anywhere. The function stack, some vtable, program data, etc. Any write to that dereferenced pointer will alter the state of your program in such a way that the behavior of your program will become undefined. There would be no way for C++ to guarantee any kind of defined behavior when you can write to arbitrary locations in memory. |
|
The other is more specifically talking about code that is deemed "undefined behaviour" by the spec. There's a surprising amount of this, and the compiler is explicitly allowed to do anything it wants when encountered, from emitting 'close enough' code to emitting no code at all, to emitting code to order a pizza to your current location.
If this is the latter case then it could result in random bits of code mysteriously doing completely unexpected things if the compiler thinks a data race there is possible. This would make it far harder to track down bugs and reason about what code might cause such.