advanced · multicore
Independent Variables That Are Not Independent
Two threads increment two different variables and never touch each other's data, yet adding the second thread makes the program slower. What is happening?
Practical scenario
A worker pool keeps a per-worker counter in a shared array indexed by worker id. Throughput drops as workers are added past two, and profiling shows time in an ordinary increment.
What it tests
- • Knowledge that coherence operates on lines, not variables
- • Whether the candidate can explain the ping-pong mechanism
- • Understanding of padding as a fix and what it costs