Expert · Module 13 · Lesson 3 of 6
Lock-Free Queues: Compare-Exchange and Reclamation
Sketch a Michael-Scott queue with compare_exchange_weak, see why ABA breaks naive reclamation, and compare hazard pointers with epoch schemes.
By the end you can
- Sketch enqueue and dequeue with compare_exchange_weak loops
- Explain the ABA problem and why freed nodes endanger lock-free code
- Compare hazard pointers and epoch reclamation for safe memory return
Builds on A Pool Allocator for Fixed-Size Nodes.
01 · A question first
Four producers push log records while two consumers drain them. A mutex around the queue serializes every push and pop, and contention doubles with each added thread. How do threads link nodes without holding a lock, and what keeps a freed node from being recycled mid-operation?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the problem
- How the idea works
- A post office slot
- Why it is correct
- What it costs
- Pitfalls and variations
- Where it is used
03 · Practice
Something wrong with this lesson? Report a problem