Hazard Pointers

Safe Memory Reclamation for lock-free structures — threads publish hazard pointers; a retired node is held until no slot references it, then freed.

protect = publish + validate scan: O(R + H·K) amortized O(1) reclaim memory bound Θ(H²·K)
Slow Fast

Threads & Hazard Slots

Thread T1 (reader)
idle
HP[T1] = null
Thread T2 (remover)
idle
HP[T2] = null

Lock-free Stack

head →

T2 Retire List

empty

What just happened

Press Auto demo, or step manually. The remover (T2) will retire a node, but the scan keeps it while T1's hazard slot still points at it.

Operation costs

OperationCostNotes
protect (publish + validate)O(1)store + StoreLoad fence + re-read; may retry
clear slotO(1)store null — unpins the node
retireO(1)append to thread-local list (never free)
scan + reclaimO(R + H·K)amortized O(1) per node at threshold ≈ 2·H·K
held memoryΘ(H²·K)bounded; stalled reader pins only its K slots

Operation log

protected (slot points here) retired / scanning freed live