Multiple ChoiceHard 45s
lock-free stack ABA mitigation
A lock-free stack using compare_exchange on a raw next pointer suffers from ABA. Which is a standard mitigation?
Options
- 1Use memory_order_relaxed for all operations, which removes the ABA window entirely
- 2Tag the pointer with a version counter packed into a wider atomic (e.g. 128-bit CAS)
- 3Call std::atomic_thread_fence after every push and pop to order the pointer updates
- 4Make the stack nodes constexpr so the popped pointer cannot be reused by an allocator
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.