|
|
|
|
|
by sunshowers
480 days ago
|
|
Unsynchronized, shared, mutable state are where data races happen. You need all three. This means there are three ways to resolve this: * Add synchronization with locks, etc. * Don't share mutable access, e.g. single-owner model with channels. * Make data immutable: an insight originally from purely functional languages. I believe Google invested quite heavily in this model with Guava. Rust lets you choose which one of the three to give up, and it also statically prevents all three from happening at the same time. |
|
That can still break if a reader makes multiple calls and implicitly assumes that the data structure at large hasn't been mutated between them.