# Race conditions and locks

Week 7 · Concurrency · Operating Systems
The page also has an interactive playground: https://alfonsocampodonico.com/classes/operating-systems/locks?lang=en
Code: https://github.com/AlfonsoCampodonico/os-playground/tree/main/src/sim (`gh repo clone AlfonsoCampodonico/os-playground`)

> Two threads, one counter and one interleaving: watch an increment get lost and a lock fix it.

counter++ is not atomic: it is three instructions. Choose when each interrupt happens and watch two threads step on each other, then try it with a lock.

**OSTEP:** chapters 26–28, and the playground reproduces its `x86.py` homework simulator, seed for seed.

The playground above keeps its whole setup in the URL, so a link to this page reproduces the exact example. Change the inputs, step through it, and share the link.
