The memory models that underlie programming languages (2016)
Rust has an interesting, and somewhat difficult, memory model.First, there's the single ownership tree. Single ownership is checked by the borrow checker. You can have only one mutable reference to a data object at a time, and that's also checked by the borrow checker. If you can stay within that model, if the program compiles, it will probably work at the data access level.But then there are all the escape hatches.There's "Rc", which is reference counting for read-only use. This works fine for immutable objects, but not for mutable ones.There's "Cell" and "RefCell". These allow multiple ownership, and only one mutable access at a time. Request mutable access via two routes and you get a panic, or an error if you use try_borrow();
The static analysis of the borrow checker is not able to figure out when you're headed for trouble via this route.There's "Arc" and "Mutex", which allows access across thread boundaries. Request access via two routes in the same thread, and you deadlock.Designing the data structures for something tightly coupled with concurrency, like a window manager or a game, is difficult.