consume 1.0.1

Memory order consume for when it's known that the compiler can't elide the dependency
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 3.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • schets/consume
    3 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • schets

This provides a consume ordering for when the compiler cannot elide the dependency

Examples

extern crate consume;
use std::sync::atomic::{AtomicPtr, AtomicUsize};

fn consume_load(pt: &AtomicPtr<*const usize>) -> usize {
    // There's a data dependency on the loaded value, 
    // meaning that the compiler can't od silly things to
    // eliminate the dependency
    unsafe { *pt.load(Consume) }
}

fn incorrect_consume_load(ind: &AtomicUsize, vals: &Vec<usize>) -> usize {
    // There is no data dependency here
    // since the compiler can eliminate the loaded value
    // from the pointer index. Ensure that you don't have this.
    // Use consume at your own risk.
    let i = ind.load(consume::Consume);
    vals[ind - ind]
    // vals[ind] would probably be correct, unless some shenanigans with the
    // bounds checking occured. I only use vec for convenience, only
    // use consume if you understand all possible data paths taken by the compiler
}