I want to share an excellent related article, "A Concurrency Cost Hierarchy" [0] by Travis Downs [1]. It was posted to HN many times [2], the largest discussion has 26 comments [3].

My own programming experience is mostly Python, so throughout the most of my career I treated locks as pure magic and didn't think much about what happens under the hood.

At some point in my life I became interested in Rust and lower-level programming and this article in particular really helped me to set my head straight on this topic. It doesn't only explain how concurrency primitives actually work, but it also explains why they work this way, what choices and trade-offs are involved.

This article uses C++ for all examples, but there are really nothing language specific, all principles will work in Rust, C, Zig etc

[0] https://travisdowns.github.io/blog/2020/07/06/concurrency-co...

[1] https://travisdowns.github.io/

[2] https://hn.algolia.com/?q=https%3A%2F%2Ftravisdowns.github.i...

[3] https://news.ycombinator.com/item?id=24489829