Crates.io | fenic |
lib.rs | fenic |
version | 0.1.0 |
source | src |
created_at | 2024-01-14 16:40:36.725959 |
updated_at | 2024-01-14 16:40:36.725959 |
description | test concurrent code |
homepage | |
repository | https://codeberg.org/fibra-rs/fenic |
max_upload_size | |
id | 1099557 |
size | 329,722 |
Testing for concurrent code.
Add this to your Cargo.toml
:
[target.'cfg(fenic)'.dependencies]
fenic = "0.7"
Next, create a test file and add a test:
use fenic::sync::Arc;
use fenic::sync::atomic::AtomicUsize;
use fenic::sync::atomic::Ordering::{Acquire, Release, Relaxed};
use fenic::thread;
#[test]
#[should_panic]
fn buggy_concurrent_inc() {
fenic::model(|| {
let num = Arc::new(AtomicUsize::new(0));
let ths: Vec<_> = (0..2)
.map(|_| {
let num = num.clone();
thread::spawn(move || {
let curr = num.load(Acquire);
num.store(curr + 1, Release);
})
})
.collect();
for th in ths {
th.join().unwrap();
}
assert_eq!(2, num.load(Relaxed));
});
}
Then, run the test with
RUSTFLAGS="--cfg fenic" cargo test --test buggy_concurrent_inc --release
Loom currently does not implement the full C11 memory model. Here is the (incomplete) list of unsupported features.
SeqCst
accesses (e.g. load
, store
, ..):
They are are regarded as AcqRel
. That is, they impose weaker
synchronization, causing Loom to generate false alarms (not complete). See
#180 for example. On the other
hand, fence(SeqCst)
is supported.load_buffering
test case in
tests/litmus.rs
.This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in fenic
by you, shall be licensed as MIT,
without any additional terms or conditions.