A hazard-pointer Treiber stack

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. ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.