Thread 1 Thread 2
---------------------------------- ----------------------------------
1. Reads x (reads 0)
[Context Switch! ⏸️]
1. Reads x (still reads 0!)
2. Adds 1 (0 + 1 = 1)
3. Writes x = 1 💾
[Context Switch! ⏸️]
2. Adds 1 (0 + 1 = 1)
3. Writes x = 1 💾 (Overwrites Thread 2!)
This is the problem in multi threading 😬😬😬