Expand description
Hazard Pointer Registry
Hazard pointers provide safe memory reclamation for lock-free data structures. When a thread reads a shared pointer, it publishes the address in a per-CPU hazard pointer slot. Before freeing memory, the reclaimer checks all hazard pointers to ensure no thread is actively referencing the object.
This is simpler than RCU for single-object protection and is used alongside RCU for different access patterns:
- RCU: read-heavy data structures with infrequent updates
- Hazard pointers: fine-grained per-object protection in lock-free containers (queues, stacks, hash maps)
Structs§
- Hazard
Guard - A guard that holds a hazard pointer slot. When dropped, the slot is cleared (set to HP_EMPTY).
Functions§
- active_
count - Get the number of active (non-empty) hazard pointer slots.
- clear_
cpu_ slots - Clear all hazard pointer slots for a given CPU.
- collect_
protected - Scan all hazard pointer slots and return a list of currently protected addresses. Used for batch reclamation: collect a retire list, then filter out any addresses that appear in the hazard set.
- is_
protected - Check whether a given address is currently protected by any hazard pointer.
- protect
- Protect a pointer by publishing it in a hazard pointer slot.