4 ms·
Agreed. The problem with mutex is that it's often hard to get right, since it's a low-level primitive for serializing access to shared memory, and it does not
by paskozdilar 4y ago
Agreed.
The problem with mutex is that it's often hard to get right, since it's a low-level primitive for serializing access to shared memory, and it does not compose (cannot atomically lock two mutexes).
CSP/Actor model simply takes the problem that mutex solves on the low level - concurrency - and makes the whole world concurrent-by-default, so that mutexes are not needed.
Note the 1st Go proverb [0]:
"Don't communicate by sharing memory, share memory by communicating."
[0] https://www.youtube.com/watch?v=PAAkCSZUG1c&t=168s https://www.youtube.com/watch?v=PAAkCSZUG1c&t=168s
- vore 4y agoSure you can compose mutexes: https://en.cppreference.com/w/cpp/thread/lock https://en.cppreference.com/w/cpp/thread/lock In practice, if you have a global total ordering of mutexes, it's safe to lock any number of them provided you lock them in order. CSP is interesting but it doesn't apply in a lot of cases, e.g. designing a lock striping mechanism over a database as described in the article would not be very fun with CSP or actors, as the article calls out at the bottom.
- paskozdilar 4y ago> In practice, if you have a global total ordering of mutexes, it's safe to lock any number of them provided you lock them in order. Very interesting! Such a simple and elegant solution.