The memory models that underlie programming languages (2016)
Rust has an interesting, and somewhat difficult, memory model.<p>First, there&#x27;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&#x27;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.<p>But then there are all the escape hatches.<p>There&#x27;s &quot;Rc&quot;, which is reference counting for read-only use. This works fine for immutable objects, but not for mutable ones.<p>There&#x27;s &quot;Cell&quot; and &quot;RefCell&quot;. 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&#x27;re headed for trouble via this route.<p>There&#x27;s &quot;Arc&quot; and &quot;Mutex&quot;, which allows access across thread boundaries. Request access via two routes in the same thread, and you deadlock.<p>Designing the data structures for something tightly coupled with concurrency, like a window manager or a game, is difficult.