race condition అనేది shared state ను access చేసే concurrent operations యొక్క అనూహ్య timing పై ఫలితం ఆధారపడే ఒక bug. classic సందర్భం atomic కాని read-modify-write.
ఇది ఎలా పనిచేస్తుంది
counter += 1 atomic గా కనిపిస్తుంది కానీ నిజానికి మూడు steps: read, add, write. రెండు threads interleave అవ్వగలవు కాబట్టి ఒక update కోల్పోతుంది.
counter = 0
Thread A: read 0 ─────────── write 1
Thread B: read 0 ─ write 1
Result: 1 (should be 2 — one increment lost)
