jonhoo / haphazard

Hazard pointers in Rust.
Apache License 2.0
197 stars 26 forks source link

What happens when a `HazardPointer` tries to protect a new pointer without first resetting protection? #28

Open anko opened 2 years ago

anko commented 2 years ago
let guard = HazardPointer::new();
let ptr1 = guard.protect_ptr(atomic1);
let ptr2 = guard.protect_ptr(atomic2); // ①
guard.reset_protection(); // ②

What does ① do? Does it drop protection for ptr1 and begin protecting ptr2? Or does it fail every time because reset_protection wasn't called in between? I think the documentation doesn't currently explicitly state this.

Similarly, I can imagine multiple things ② might do.

jonhoo commented 2 years ago

The former — protecting a new pointer stops protecting the old pointer. A given hazard pointer can only protect at most one pointer at the time. I totally agree this should be explicit in the documentation!