Crates.io | jthread |
lib.rs | jthread |
version | 0.1.1 |
source | src |
created_at | 2023-12-19 00:05:54.969357 |
updated_at | 2023-12-19 00:20:21.611948 |
description | Deadlock-free Mutual Exclusion locks for Rust |
homepage | |
repository | https://github.com/MovAh13h/jthread-rs |
max_upload_size | |
id | 1073819 |
size | 41,249 |
JThread is a Rust library designed to facilitate advanced mutex management in multi-threaded environments while providing deadlock-freedom. It provides mutexes with fine-grained control, and custom error handling, tailored for achieving deadlock-freedom.
Region
and JMutex
for advanced mutex locking strategies.JError
) for specific mutex and region-related errors.sync
macro for easy and safe locking of one or more mutexes.Add this to your Cargo.toml
:
[dependencies]
jthread = "0.1.0"
Lock creation:
use jthread::{JMutex, Region};
let region = Region::new();
let mutex = JMutex::new(5, region); // Protecting an integer
Using the sync
macro:
use jthread::{JMutex, sync, Region};
let data_mutex = JMutex::with_default(5); // Protecting an integer
let result = sync!([data_mutex], |data_guard| {
*data_guard += 1; // Modify the data
*data_guard
});
Our tests
module has the infamous Dining Philosophers problem setup using JThread. Feel free to refer to the variations provided in the module as advanced example usage.
The library includes a comprehensive test suite demonstrating its capabilities, especially in complex multi-threading scenarios. Refer to the tests module for examples and usage patterns.
For more detailed information on each component and method, refer to the inline documentation within the library source code, generated using Rust's standard documentation tool, cargo doc
.