light-qsbr

Crates.iolight-qsbr
lib.rslight-qsbr
version1.0.2
created_at2025-08-24 23:42:20.728857+00
updated_at2025-08-29 18:00:11.073059+00
descriptionA lightweight Quiescent-State-Based Reclamation (QSBR) library for safe memory reclamation in lock-free and async runtimes.
homepagehttps://github.com/orengine/light-qsbr
repositoryhttps://github.com/orengine/light-qsbr
max_upload_size
id1808898
size55,790
Eugene (Eugene-Usachev)

documentation

https://docs.rs/light-qsbr

README

light-qsbr

A lightweight Quiescent-State-Based Reclamation (QSBR) library for Rust.

It provides a minimal, efficient mechanism for safe memory reclamation in concurrent and asynchronous runtimes, without the complexity of a garbage collector or hazard pointers.


โœจ Features

  • ๐Ÿš€ Extremely lightweight โ€” only the essential QSBR pieces.
  • ๐Ÿงต Thread-local memory managers with a global epoch coordinator.
  • ๐Ÿ—‘๏ธ Safe reclamation of memory scheduled by executors.
  • ๐Ÿ› ๏ธ Designed for async runtimes and lock-free data structures.

๐Ÿ“š Core Concepts

  • SharedManager
    The global manager. Tracks the current epoch and number of executors.

  • LocalManager
    The thread-local manager. Each executor registers one and uses it to schedule memory for deallocation or dropping.

  • Epochs
    Executors periodically advance epochs. Memory is only freed once all executors have passed the epoch in which the memory was retired.


โšก Quick Example

use light_qsbr::{SharedManager, local_manager};
use light_qsbr::orengine_utils::OrengineInstant;

fn main() {
    // Create the global manager
    let shared = SharedManager::new();

    // Register an executor for this thread
    shared.register_new_executor();

    // Schedule deallocation
    let value = Box::new(42);
    let ptr = Box::into_raw(value);
    unsafe {
        local_manager().schedule_deallocate(ptr);
    }

    // Periodically (better when runtime is polling) try to pass the epoch
    local_manager().maybe_pass_epoch(OrengineInstant::now());

    // Deregister before thread exit
    unsafe { LocalManager::deregister() };
}

โœ… When to Use

  • Implementing lock-free collections that need safe reclamation.

  • Async runtimes that want QSBR without the overhead of hazard pointers.

  • Situations where you control the executor lifecycle and can enforce correct registration/deregistration.

๐Ÿšซ When Not to Use

  • If executors come and go frequently (executors are short-lived).

  • If you want fully automatic memory management (this is not a GC).

Commit count: 27

cargo fmt