cacheguard 0.1.0

A lightweight cache guard that pads atomics to prevent false sharing in concurrent Rust systems
Documentation
  • Coverage
  • 0%
    0 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 13.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 983.64 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • fereidani/cacheguard
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fereidani

CacheGuard

** A lightweight cache guard that pads atomics to prevent false sharing in concurrent Rust systems **

Crates.io Documentation MIT licensed

CacheGuard is primarily used to pad atomic variables to prevent cache invalidation that can occur due to atomic operations. By aligning memory according to the target architecture's cache size rules, CacheGuard mitigates false sharing and enhances performance, particularly in concurrent environments.

Difference with Crossbeam CachePadded

While both CacheGuard and Crossbeam CachePadded aim to mitigate cache invalidation issues, there are key differences:

  • CacheGuard is a standalone crate designed specifically for padding atomic types, whereas Crossbeam CachePadded is a part of the broader crossbeam-utils ecosystem.
  • CacheGuard is tuned for worst-case and not most common scenarios and also supports a wider range of platforms.
  • CacheGuard uses a code generation approach to dynamically read rustc target platforms, which simplifies maintenance and allows for tailored library code generation.
  • This design makes CacheGuard more specialized and easier to maintain as it directly targets the needs of preventing cache invalidation in concurrent environments.

Usage

Add CacheGuard to your Cargo.toml:

[dependencies]
cacheguard = "0.1"

Wrap your atomic pointers with CacheGuard to ensure proper memory alignment. For example, you can create a struct that holds two atomic pointers wrapped in CacheGuard as follows:

use cacheguard::CacheGuard;
use std::sync::atomic::{AtomicUsize, Ordering};

struct ConcurrentStructure {
    counter1: CacheGuard<AtomicUsize>,
    counter2: CacheGuard<AtomicUsize>,
}

This example demonstrates wrapping two atomic counters within a struct using CacheGuard.

License

This project is licensed under the MIT License.