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.

Start: step 1

6 steps · progress is saved in this browser

  1. Why count++ loses updatesJava · BasicsTwo threads each run count++ once. The result can be 1, not 2.
  2. Why count++ loses updates in goroutinesGo · BasicsTwo goroutines each run count++ once. The result can be 1, not 2.
  3. 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.
  4. Thread-safe collectionsJava · IntermediateTwo threads add to one ArrayList. Both write into the same slot, and one element is lost.
  5. 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.
  6. DeadlockJava · IntermediateT1 holds A and wants B. T2 holds B and wants A. Each waits for the other, forever.

All learning paths · All scenarios