Skip to content

Commit

Permalink
docs: fix readme and lib examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromfedricci committed Nov 4, 2024
1 parent 9622d92 commit 93f5fd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ fn main() {
// A queue node must be mutably accessible.
// Critical section must be defined as a closure.
let mut node = MutexNode::new();
*c_mutex.lock(&mut node) = 10;
c_mutex.lock_with_then(&mut node, |data| {
*data = 10;
});
})
.join().expect("thread::spawn failed");

// A queue node must be mutably accessible.
// A node is transparently allocated in the stack.
// Critical section must be defined as a closure.
let mut node = MutexNode::new();
assert_eq!(*mutex.try_lock(&mut node).unwrap(), 10);
assert_eq!(*mutex.try_lock_then(|data| *data.unwrap()), 10);
}
```

Expand Down Expand Up @@ -128,7 +129,7 @@ fn main() {

// Local node handles are provided by reference.
// Critical section must be defined as a closure.
assert_eq!(mutex.try_lock_with_local_then(&NODE, |g| *g.unwrap()), 10);
assert_eq!(mutex.try_lock_with_local_then(&NODE, |data| *data.unwrap()), 10);
}
```

Expand All @@ -138,7 +139,7 @@ This implementation will have non-waiting threads race for the lock against
the front of the waiting queue thread, which means this it is an unfair lock.
This implementation is suitable for `no_std` environments, and the locking
APIs are compatible with the [lock_api] crate. See [`barging`] and
[`barking::lock_api`] modules for more information.
[`barging::lock_api`] modules for more information.

```rust
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
//! })
//! .join().expect("thread::spawn failed");
//!
//! // A node is transparently allocated in the stack.
//! // Critical section must be defined as a closure.
//! assert_eq!(mutex.try_lock_then(|data| *data.unwrap()), 10);
//! ```
Expand Down

0 comments on commit 93f5fd0

Please sign in to comment.