pub struct DFMutex<T> { /* private fields */ }Expand description
Deadlock-free Mutex locks
DFMutex is a library that provides a guaranteed deadlock-free Mutex implementation for the Rust language. Based on the research paper Higher-Order Leak and Deadlock Free Locks by Jules Jacobs and Stephanie Balzer.
Example
use dfmutex::{DFMutex, spawn};
fn main() {
// Create a Mutex with any owned value
let m = DFMutex::new(String::from("Lorem Ipsum"));
// Create a closure to pass in the thread.
// The type of the created Mutex above should be same as the
// argument to the closure.
let closure = |mut dfm: DFMutex<String>| {
let data = dfm.lock().unwrap();
// Use the data
println!("{}", data);
};
// Spawn 8 threads and store their handles
let mut handles = Vec::new();
for _ in 0..8 {
handles.push(spawn(&m, closure));
}
// Join all the threads
for handle in handles.into_iter() {
handle.join().unwrap();
}
}A deadlock-free mutual exclusion primitive useful for protecting shared data
Implementations§
Source§impl<T> DFMutex<T>
impl<T> DFMutex<T>
Sourcepub fn lock(&mut self) -> LockResult<MutexGuard<'_, T>>
pub fn lock(&mut self) -> LockResult<MutexGuard<'_, T>>
Acquires a mutex, blocking the current thread until it is able to do so.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DFMutex<T>
impl<T> RefUnwindSafe for DFMutex<T>
impl<T> Send for DFMutex<T>where
T: Send,
impl<T> Sync for DFMutex<T>where
T: Send,
impl<T> Unpin for DFMutex<T>
impl<T> UnwindSafe for DFMutex<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more