Skip to content

Commit fe49947

Browse files
committed
update mutex.rs to fix corrections
1 parent ff00b7d commit fe49947

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

library/std/src/sync/mutex.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ pub struct Mutex<T: ?Sized> {
195195
/// and `T` can be sent across thread boundaries. This is crucial for allowing
196196
/// safe access to the protected data from multiple threads.
197197
///
198-
/// - `Sync` is implemented for `Mutex<T>` if and only if `T` is both `Send` and
199-
/// `Sync`. This ensures that `Mutex<T>` can be safely shared between threads
198+
/// - `Sync` is implemented for `Mutex<T>` if and only if `T` is `Send`,
199+
/// since passing around a &Mutex<T> is basically the same as passing a &mut T.
200+
/// This ensures that `Mutex<T>` can be safely shared between threads
200201
/// without requiring further synchronization, assuming `T` can be sent across
201202
/// thread boundaries. It guarantees that multiple threads can safely access the
202203
/// protected data concurrently without data races.
@@ -209,23 +210,6 @@ pub struct Mutex<T: ?Sized> {
209210
#[stable(feature = "rust1", since = "1.0.0")]
210211
unsafe impl<T: ?Sized + Send> Send for Mutex<T> {}
211212

212-
/// SAFETY
213-
///
214-
/// The `Send` and `Sync` implementations for `MutexGuard` ensure that it is
215-
/// safe to share instances of `MutexGuard` between threads when the protected
216-
/// data is also thread-safe. The following explains the safety guarantees:
217-
///
218-
/// - `MutexGuard` is not `Send` because it represents exclusive access to the
219-
/// data protected by `Mutex`, and sending it to another thread could lead to
220-
/// data races or other unsafe behavior, violating the mutual exclusion property
221-
/// provided by `Mutex`.
222-
///
223-
/// - `Sync` is implemented for `MutexGuard` if and only if `T` is `Send`. This
224-
/// ensures that `MutexGuard` can be safely shared between threads if the
225-
/// protected data can be sent across thread boundaries. It guarantees that
226-
/// multiple threads can safely access the protected data concurrently without
227-
/// data races.
228-
///
229213
#[stable(feature = "rust1", since = "1.0.0")]
230214
unsafe impl<T: ?Sized + Send> Sync for Mutex<T> {}
231215

0 commit comments

Comments
 (0)