Multiple mutable reference

Hello everybody,
I have a simple questione.

It is pretty obvious that multiple mutable reference is a big problem for data race, but there is also another real point behind it? I mean, some like compilation optimization?

I could not think that the real problem behind multiple mutable reference is just data race.

Can anyone give me more detail about it?

Thanks in advance.

1 Like

Holding an &mut represents exclusive access to the pointee, so the optimizer is free to reorder or eliminate operations freely as long as the final state is the same as specified by the program text. Any concurrent access to the pointee (read or write) is UB because it might observe some intermediate states that shouldn’t occur according to the sequence of operations as written in the source code.

4 Likes

See also Why Aliasing Matters

5 Likes

See also the answers in this recent related thread:

where e.g. the following article was linked

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.