You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think a mutex is a good idea for this course since we don't handle any form of concurrency here.
A good analogy to explain Cell/RefCell could be the mutable keyword from C++. In combination with a better example, maybe something about caching values or lazy initialisation, this should the concept pretty easy to grasp.
The argument for Mutex is that it's a pretty familiar way to ensure, at runtime, that only one thing is accessing the value inside. Which is really the crux of interior mutability: you can get an exclusive reference from an immutable reference, but somehow you need to guarantee that is the only one.
Cell just has methods that take &self but actually mutate the value (and references concurrency for the safety of this operation), while RefCell is a new concept.
At any rate, I think the slide should focus on the concept, leaving the particular std type used to achieve the interior mutability as an incidental detail.
Cell and RefCell are pretty advanced for introducing interior mutability -- a mutex is much more familiar territory.
Mention Cell and RefCell in the speaker notes as alternatives to Mutex for more specific situations.
The text was updated successfully, but these errors were encountered: