The introduction of the Treiber stack in the previous section on reference counting was not an idle introduction. We'll examine hazard pointers and epoch-based reclamation here, through the lens of an effectively reclaimed Treiber stack. It so happens that conc ships with a Treiber stack, in tfs/conc/src/sync/treiber.rs. The preamble is mostly familiar:
use std::sync::atomic::{self, AtomicPtr}; use std::marker::PhantomData; use std::ptr; use {Guard, add_garbage_box};
Both Guard and add_garbage_box are new, but we'll get to them directly. The Treiber struct is as you might have imaged it:
pub struct Treiber<T> { /// The head node. head: AtomicPtr<Node<T>>, /// Make the `Sync` and `Send` (and other OIBITs) transitive. ...