Learning paths / Shared state, three languages
Shared state, three languages
The same lost update in Java, Go and Rust, then the collections and maps that break the same way.
- Why count++ loses updatesJava · BasicsTwo threads each run count++ once. The result can be 1, not 2.
- Why count++ loses updates in goroutinesGo · BasicsTwo goroutines each run count++ once. The result can be 1, not 2.
- Sharing a counter between threads with Arc<Mutex<T>>Rust · BasicsTwo threads add 1 to a shared counter. The second waits in lock() until the first drops its guard.
- Thread-safe collectionsJava · IntermediateTwo threads add to one ArrayList. Both write into the same slot, and one element is lost.
- fatal error: concurrent map writes, explainedGo · IntermediateTwo goroutines write one plain map at the same time. The Go runtime notices and stops the whole program.
- DeadlockJava · IntermediateT1 holds A and wants B. T2 holds B and wants A. Each waits for the other, forever.