Skip to content

A Rust implementation of a shared mutex (readers-write lock) using the busy-forbidden protocol

Notifications You must be signed in to change notification settings

mlaveaux/bf-sharedmutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

benchmarking

Benchmarking various implementations of readers-writer locks, std::sync::RwLock, parking_lot::RwLock, tokio::sync::RwLock.

cargo criterion --message-format=json > tmp/benchmark.json

We compare several different Rust implementations of readers-writer locks.

LLVM Sanitizer

For Linux targets it is also possible to run the LLVM address sanitizer to detect memory issues in unsafe and C++ code. This requires the nightly version of the rust compiler, which can acquired using rustup toolchain install nightly. To show the symbols for the resulting stacktrace it is also convenient to install llvm-symbolizer, for example using sudo apt install llvm on Ubuntu. Afterwards, the tests can be executed with the address sanitizer enabled using cargo +nightly xtask address-sanitizer. Similarly, we can also the thread sanitizer to detect data races using cargo +nightly xtask thread-sanitizer.

Code Coverage

Code coverage can be automatically generated for the full workspace using a cargo task. The code coverage itself is generated by LLVM with source code instrumentation, which requires the preview tools to be installed rustup component add llvm-tools-preview, and grcov, which can be acquired using cargo install grcov. To execute the code coverage task use cargo xtask coverage. The resulting HTML code coverage report can be found in target/coverage.

Concurrency testing

Using the crate loom it is actually possible to test all possible interleavings defined by the C11 memory standard to show that the shared mutex is data race free. This can be used as follows:

RUSTFLAGS="--cfg loom" cargo test

If a violation is detected the following command can be used to show the exact trace and source code locations of read and write accesses.

LOOM_LOG=trace \
LOOM_LOCATION=1 \
LOOM_CHECKPOINT_INTERVAL=1 \
RUSTFLAGS="--cfg loom" \
cargo test --test <test_name> --release

Related work

About

A Rust implementation of a shared mutex (readers-write lock) using the busy-forbidden protocol

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages