Skip to content

Commit

Permalink
Add example mutex use
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgreig committed Aug 8, 2023
1 parent 7ac14a6 commit 09ba0e7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ use core::cell::{Ref, RefCell, RefMut, UnsafeCell};

/// A mutex based on critical sections.
///
/// # Example
///
/// ```no_run
/// # use critical_section::Mutex;
/// # use std::cell::Cell;
///
/// static FOO: Mutex<Cell<i32>> = Mutex::new(Cell::new(42));
///
/// fn main() {
/// critical_section::with(|cs| {
/// FOO.borrow(cs).set(43);
/// });
/// }
///
/// fn interrupt_handler() {
/// let _x = critical_section::with(|cs| FOO.borrow(cs).get());
/// }
/// ```
///
///
/// # Design
///
/// [`std::sync::Mutex`] has two purposes. It converts types that are [`Send`]
Expand Down

0 comments on commit 09ba0e7

Please sign in to comment.