Multicore & Synchronization
Which describes false sharing in a multithreaded program?
- AThreads update different variables that sit in the same cache line, so the line bounces between cores and slows things down
- BTwo threads update the same variable without synchronization and corrupt it
- CThreads wait on each other's locks and stop
Show answer and explanation
Answer: A. Threads update different variables that sit in the same cache line, so the line bounces between cores and slows things down
Coherence is managed per cache line, typically 64 bytes. Even if core 0 writes only a and core 1 writes only b, when a and b share a line each write invalidates the other's copy and the line bounces between the cores. The results are correct but performance drops sharply: this is false sharing. It often occurs with arrays of per-thread counters.
- A. Correct. The data is not shared, but the line is.
- B. That is a data race.
- C. That is a deadlock.