3 ms·
Calling a method on an object could potentially alter the internal state of that object. So in the context of some sort of concurrent execution, calling a metho
by polyglotfacto 6y ago
Calling a method on an object could potentially alter the internal state of that object. So in the context of some sort of concurrent execution, calling a method implies first of all having a direct reference to the object from the thread of execution where the method call occurs, and then it also implies having to synchronize potential state changes(writes) with other threads of execution who might also have a reference to the object and call methods on it.
On the other hand, sending a message would allow for only a single thread of execution owning that object, and calling methods on the object in response to incoming messages.
So I'd say it's not really "sending a message to an object", it's rather "sending a message to some kind of thread of execution, which owns that object uniquely".
Result: there is a "single writer" with regards to the internal state of that object.
I actually wrote an article on this for Rust, perhaps it could help rewiring your mental model: https://medium.com/@polyglot_factotum/rust-concurrency-the-single-writer-principle-applied-aada2cdc6fb0 https://medium.com/@polyglot_factotum/rust-concurrency-the-s...