▲ | adwn 4 days ago | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> The standard way to avoid these problems is to use locks to prevent data updates from happening at the same time. This causes big performance hits […] No. Modern mutex implementations [1] are extremely efficient, require only 1 byte of memory (no heap allocation), and are almost free when there's no contention on the lock – certainly much faster and much lower latency than sending messages between actors. [1] Like the parking_lot crate for Rust. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | alfanerd 4 days ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sending a message between Actors can be just moving a pointer to a piece of shared memory. I think sending messages is more about the way you think about concurrency, more than the implementation. I have always found the "one thread doing "while True receive message, handle message" much easier to reason about than "remember to lock this chunk of data in case more than one thread should access it" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | senderista 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Nit: you can’t have a 1-byte mutex unless you implement your own wait queues like parking_lot does. Any purely futex-based mutex (ie delegating all the blocking logic to futex syscalls) must be at least 4 bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | adwn 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Why is this downvoted? It's factually correct, on-topic, and relevant (because it contradicts a claim on the linked website). If you disagree, say so and we can discuss it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | otabdeveloper4 4 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A contended mutex is a system call and likely stalls all the CPUs on your machine. Lockfree spinlocks will only waste cycles on one CPU. A huge difference when you have dozens and hundreds of cores. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|