Under the Hood
Loading visualizer…
DNSresolving host
TCPconnecting
TLShandshake
HTTPrequesting
Initializing Sorting Algorithms...
Sorting
Trees
Graphs
Preparing interactive visualizations...
Under the Hood
Loading visualizer…
Why counter++ isn't atomic, how a mutex prevents data corruption, what creates a deadlock, and how lock ordering breaks the cycle.
——Two threads each increment a shared counter 1 000 times — expected final value: 2 000. The increment operation is NOT atomic: it compiles to three CPU instructions: READ the value into a register → ADD 1 → WRITE back. Any context switch between these three steps corrupts the result.
Two threads each run counter++ 1 000 times. Without synchronization, what is the most likely final value?