3 ms·
Writing shared-state thread safe code is very hard to get right especially in the context of large systems. When you move beyond safely coordinating mutation of
by maximilianburke 16y ago
Writing shared-state thread safe code is very hard to get right especially in the context of large systems. When you move beyond safely coordinating mutation of shared resources there are many other headaches that can pop up, like priority inversion issues, lock ordering problems, etc.
Atomic operations are not a panacea either. Lock free data structures are very difficult to write correctly and the performance benefits associated with using atomics can start to evaporate when there is contention between multiple threads. There are also numerous subtle problems that can arise, from data visibility problems when modifying an unaligned address on multi-socket x86 platforms to ABA problems.
The easiest to write, and safest, multithreaded code is that which shares no state. Saying that atomic operations are the way to go is like saying NoSQL is the way to go, they are useful for a subset of problems but in general they are the wrong level at which to be thinking when approaching concurrency.