3 ms·
Curious, can you elaborate on what are the issues of mutability in single-threaded code?
by newlisp 5y ago
Curious, can you elaborate on what are the issues of mutability in single-threaded code?
- scottlamb 5y agoIt comes down to how a language construct allocates freedom to the programmer vs the optimizing compiler. * Rust references are strict. &mut references guarantee that nothing else can access the backing memory while the &mut is valid. & references guarantee that nothing (including &mut by the rule above, or unsafe code with raw pointers by programmer's pinkie swear) can change the backing memory while the &mut is valid. This allows the compiler to perform more optimizations behind the scene, like assuming a value loaded into a register is still up-to-date, even if there's been a function call between. * Rust raw pointers make no guarantees (but require the programmer to type "unsafe" to use). * C pointers are IMHO weirder. iirc, two pointers of the same type may alias (unless you use the rare "restrict" keyword), but two pointers of different type can't, unless one is "char*". * AFAIK, Go pointers are at least as permissive as C's. They might not make any aliasing guarantees at all. * Other languages vary...
- steveklabnik 5y agohttps://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/ https://manishearth.github.io/blog/2015/05/17/the-problem-wi...