All challenges
Multiple ChoiceIntermediate 45s

False sharing in per-thread counters

Eight threads each increment their own int counter stored as adjacent members of one struct array. Throughput is terrible. Most likely cause and fix?
Options
  1. 1ABA problem; use tagged pointers on each counter node
  2. 2Memory leak; use unique_ptr to reclaim each counter's storage
  3. 3False sharing; pad/align each counter to a cache line
  4. 4Missing seq_cst; add fences around every counter increment

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle