Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schets/consume
Consume memory ordering in rust
https://github.com/schets/consume
Last synced: 20 days ago
JSON representation
Consume memory ordering in rust
- Host: GitHub
- URL: https://github.com/schets/consume
- Owner: schets
- License: mit
- Created: 2017-02-26T01:01:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T01:08:09.000Z (almost 8 years ago)
- Last Synced: 2024-11-18T21:42:58.944Z (about 1 month ago)
- Language: Rust
- Size: 1.95 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
This provides a consume ordering for when the compiler cannot elide the dependency
# Examples
```rust
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 {
// 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
}```