by hackyhacky · 6mo ago · 0 comments
* Have an "increment" message that adds n to the current value and returns the old value.
* Have separate "read" and "write" messages, where the "write" message is parameterized by a timestamp returned by the "read" message. If the owner detects that the timestamp sent by the write is older than the most recent timestamp, it's rejected.
Because messages are handled serially, it's easy and safe to create messages that behave sanely event without explicit locks.
Same as you wouldn't implement the "plus 2" program in an OO, functional, or this way, because of race conditions.
Either way, it's up to programmer discipline.
Can you explain how a serially-executed "increment" message in an actor system, as I've described above, would cause a race condition?
In an OOP system you could do the same, you'd just have to build the thread-safe message queue yourself. In actor languages it's built in.
There are cases where you can get race conditions in actor languages, but I'm pretty sure this isn't one.
Did someone claim otherwise?
> The actor model doesn’t eliminate race conditions by itself.
Sure, and the actor model was never marketed as "a tool to eliminate race conditions." That's not what it's for.
You have to use your tools correctly. One benefit of the actor model is that the tool eliminates large categories of race conditions (but not all of them). One benefit of garbage collection is that the tool eliminates large categories of memory errors (but not all of them). The same can be said of anything, from high-level languages, to debuggers, to linters, the IDEs, etc. Just because a tool is not a "silver bullet" does not mean that it does not deliver a strong advantage for the programmer.