3 ms·
Rust has this as well but makes you explicitly state it using a wrapper type called refcell (internal vs external borrow checking, I think are the terms). The
by junon 3y ago
Rust has this as well but makes you explicitly state it using a wrapper type
called refcell (internal vs external borrow checking, I think are the terms).
They're faster than mutexes, which themselves also internal borrow check, but also have the logic mechanic.
This allows you to make any type work similarly but eschew the overhead in cases where it's not needed.
- bonzini 3y agoSort of, refcell still enforces that shared and mutable borrows cannot coexist. A similar case to what the parent describes is RCU or crossbeam's epoch-based reclaim.
- iudqnolq 3y agoNo, RefCell relaxes the rules from requiring the borrowcheck rules be provably always followed at compile time to requiring the borrowcheck rules be actually followed in the codepaths actually run at runtime. You still can't have a mutation concurrently with a reader.