Skip to content

Commit

Permalink
fix wrong sync impl for mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Aug 10, 2024
1 parent 9e5a3bf commit 3251c85
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion maitake-sync/src/blocking/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,18 @@ where
}

unsafe impl<T: Send, Lock: Send> Send for Mutex<T, Lock> {}
unsafe impl<T: Sync, Lock: Sync> Sync for Mutex<T, Lock> {}
/// A `Mutex` is [`Sync`] if `T` is [`Send`] and `Lock` is [`Sync`].
///
/// `T` must be [`Send`] because shared references to the `Mutex` allow mutable
/// access to `T` (via a [`MutexGuard`] or [`Mutex::with_lock`]), which can be
/// used to move `T` between threads using [`core::mem::replace`] or similar.
/// `T` does **not** need to be [`Sync`], and, in fact, a `Mutex` is often used
/// to protect `!Sync` data.
///
/// The `Lock` type must be `Sync` because sharing references to a mutex
/// implicitly share references to the `Lock` type as well --- locking the mutex
/// references it.
unsafe impl<T: Send, Lock: Sync> Sync for Mutex<T, Lock> {}

// === impl MutexGuard ===

Expand Down

0 comments on commit 3251c85

Please sign in to comment.