1
2
Fork
You've already forked housekeeping
1
A concurrent memory reclamation library for Rust.
  • Rust 100%
2026年04月04日 06:26:38 +02:00
LICENSES Set up stub 2026年01月23日 08:44:02 +01:00
src [guard] Polish documentation 2026年04月04日 06:22:52 +02:00
tests Rename '[Raw]Guard' to '[Raw]Handle' 2026年04月04日 03:18:52 +02:00
.gitignore Set up stub 2026年01月23日 08:44:02 +01:00
Cargo.lock Bump to version 0.0.3 2026年04月04日 06:26:38 +02:00
Cargo.toml Bump to version 0.0.3 2026年04月04日 06:26:38 +02:00
README.md Polish the 'README' 2026年04月04日 06:25:30 +02:00
REUSE.toml Set up stub 2026年01月23日 08:44:02 +01:00

housekeeping: Cleaning up while you're away

housekeeping is a concurrent memory reclamation library for Rust; it helps build complex concurrent data structures. It is inspired by seize and crossbeam_epoch, but is simpler and offers lower-level interfaces.

With housekeeping, you can protect concurrent memory, allowing concurrent objects to be deallocated at a safe time. This is more powerful than reference counting with Arc, and is more efficient.

Usage

housekeeping has two components: Cleanups, which is global state for synchronizing threads and pending deallocation operations; and Guard, a per-thread handle to the Cleanups which protects concurrent memory access and allows concurrent objects to be deallocated safely.

// Global state for deferring deallocations (i.e. cleanups).
letcleanups=Arc::new(Cleanups::new());// An atomic variable, pointing to memory protected by 'cleanups'.
letdata: AtomicPtr<Data>;letdata: Box<Data>=Default::default();letdata_ptr=Box::into_raw(data);data=AtomicPtr::new(data_ptr);std::thread::scope(|s|{s.spawn(||{// Obtain a guard for safely handling concurrent memory.
letguard=cleanups.clone().register();// Replace the existing data.
letnew_data: Box<Data>=Box::new(somehow_compute());letnew_data_ptr=Box::into_raw(new_data);letold_data_ptr=data.swap(new_data_ptr,Ordering::AcqRel);// Defer the cleanup of the existing data.
// SAFETY:
// - '*mut Data' can be sent between threads safely.
// - The closure is 'move' and is 'static.
unsafe{guard.defer_unchecked(move||{mem::drop(Box::from_raw(old_data_ptr))})};});// Obtain a guard for safely handling concurrent memory.
letguard=cleanups.clone().register();// Use the data.
letdata_ptr=data.load(Ordering::Acquire).cast_const();// SAFETY: Safe as long as 'guard' is held.
somehow_consume(unsafe{&*data_ptr});});// Drop the last instance of the data.
let_=unsafe{Box::from_raw(data.into_inner())};

Origin

housekeeping is being developed for krabby, an experimental Rust compiler, with different goals and limitations compared to seize and crossbeam_epoch. It is offered as a standalone crate in the hope that it may prove useful for other concurrent data structure libraries.

License

Copyright (C) 2026 arya dradjica (hut1zulljl4lxd2h@bal-e.org)

housekeeping is available under the MIT or Apache-2.0 licenses, at your option. Their terms are available in LICENSES/MIT.txt and LICENSES/Apache-2.0.txt respectively.