This is for the "hazard pointer" algorithm, a lock-free algorithm in multi-threaded environments.
The hazard pointer algorithm works like this:
- save the global pointer to a local pointer.
- put the local pointer to hazard pointer list to show others can't reclaim it.
I run into an issue that how can we make sure the global pointer is not reclaimed before step 2?
void *local_p = global_p;
put_local_p_to_hazard_list(local_p);
Before the call to put_local_p_to_hazard_list()
, the local_p
may be reclaimed; how can I avoid that?