▲ | otabdeveloper4 4 days ago | |
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. | ||
▲ | gpderetta 4 days ago | parent | next [-] | |
So does a contended queue. As much as I might like the model, message passing is not a silver bullet. Any sufficiently complex message passing system will end up implementing shared memory on top of it... and mutexes. | ||
▲ | adwn 4 days ago | parent | prev [-] | |
> A contended mutex is a system call […] Because modern mutexes are so cheap (only 1 byte directly in the data structure, no heap allocation), you can do very fine-grained locking. This way, a mutex will almost never be contended. Keep in mind that a reader waiting on an empty queue or a writer waiting on a full queue will also involve syscalls. > […] and likely stalls all the CPUs on your machine. Huh? Where did you get this idea? Only the waiting thread will be blocked, and it won't "stall" the core, let alone the entire CPU. By the way, if all your threads are waiting on a single mutex, then your architecture is wrong. In the equivalent case, all your actors would be waiting on one central actor as well, so you'd have the same loss of parallelism. |