Hard
Hazard pointers vs epoch-based reclamation
A lock-free list is read by many threads without holding any lock, so a writer that unlinks a node cannot simply delete it: some reader might still be dereferencing it. Given the hazard-pointer read pattern shown, which statement best contrasts hazard pointers with epoch-based reclamation (EBR) as solutions to this problem?
main.cpp
// Hazard-pointer read of a shared lock-free list node
Node* readNode(std::atomic<Node*>& src, std::atomic<Node*>& hazardSlot) {
Node* p;
do {
p = src.load(std::memory_order_acquire);
hazardSlot.store(p, std::memory_order_release); // "I'm using p"
} while (p != src.load(std::memory_order_acquire)); // re-check p wasn't swapped out
return p;
}
// Before freeing a retired node, the reclaimer must scan every thread's
// hazard slot and confirm none currently holds that node's address.19 of 51 in Concurrency