All challenges
Multiple ChoiceHard 45s

Why compare_exchange_weak is preferred in loops

Why is compare_exchange_weak often preferred inside a CAS retry loop compared to compare_exchange_strong?
Options
  1. 1It never fails spuriously and so is always faster than compare_exchange_strong in any loop
  2. 2It provides stronger memory ordering guarantees than compare_exchange_strong on all platforms
  3. 3It cannot be used together with memory_order_relaxed, unlike compare_exchange_strong
  4. 4It may fail spuriously but can compile to cheaper instructions on some architectures

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