Module hazard_pointer

Source
Expand description

Hazard pointers.

§Example

use std::ptr;
use std::sync::atomic::{AtomicPtr, Ordering};
use cs431_homework::hazard_pointer::{collect, retire, Shield};

let shield = Shield::default();
let atomic = AtomicPtr::new(Box::leak(Box::new(1usize)));
let protected = shield.protect(&atomic);
assert_eq!(unsafe { *protected }, 1);

// unlink the block and retire
atomic.store(ptr::null_mut(), Ordering::Relaxed);
unsafe { retire(protected); }

// manually trigger reclamation (not necessary)
collect();

Modules§

hazard 🔒
retire 🔒

Structs§

HazardBag
Global bag (multiset) of hazards pointers. HazardBag.head and HazardSlot.next form a grow-only list of all hazard slots. Slots are never removed from this list. Instead, it gets deactivated and recycled for other Shields.
RetiredSet
Thread-local list of retired pointers.
Shield
Represents the ownership of a hazard pointer slot.

Constants§

RETIRED 🔒
Default thread-local retired pointer list.

Statics§

HAZARDS
Default global bag of all hazard pointers.

Functions§

collect
Frees the pointers that are retired by the current thread and not protected by any other threads.
retire
Retires a pointer.