-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation to Send
& Sync
impls
#122856
Comments
for Mutex in particular, elsewhere we document: /// A mutual exclusion primitive useful for protecting shared data
///
/// This mutex will block threads waiting for the lock to become available. The
/// mutex can be created via a [`new`] constructor. Each mutex has a type parameter
/// which represents the data that it is protecting. The data can only be accessed
/// through the RAII guards returned from [`lock`] and [`try_lock`], which
/// guarantees that the data is only ever accessed when the mutex is locked.
///
this makes the Mutex safety docs for these unsafe impls slightly tautological: "why is this Sync? because we guarantee threads are blocked until they get the lock, thus taking care of data races. why do we block and make people wait? to make this soundly Sync. why must it be Send to be Sync? because if it's not Send, it's not capable of being accessed safely from multiple threads at all." so it's mostly organizing data already there into something nicely written. bikeshed prone, but """easy""" (if you are a decent writer). |
I suppose that is possibly not easy. 🤔 subjective. |
I would assume that Also I do understand the problem. We cannot have, for example I think it is a good idea to add this example in some place:
Also |
i would like to pick this up, and improve the docs |
@Psalmuel01 Go for it! |
you didnt assign to me yet. ive worked on it, do i just go ahead and create a pr |
docs: Documented Send and Sync requirements for Mutex + MutexGuard This an attempt to continue where rust-lang#123225 left off. I did some light clean up from the work done in that PR. I also documented the `!Send` + `Sync` implementations for `MutexGuard` to the best of my knowledge. Let me know if I got anything wrong 😄 fixes rust-lang#122856 cc: `@IoaNNUwU` r? `@joboet`
Rollup merge of rust-lang#135684 - ranger-ross:mutex-docs, r=joboet docs: Documented Send and Sync requirements for Mutex + MutexGuard This an attempt to continue where rust-lang#123225 left off. I did some light clean up from the work done in that PR. I also documented the `!Send` + `Sync` implementations for `MutexGuard` to the best of my knowledge. Let me know if I got anything wrong 😄 fixes rust-lang#122856 cc: ``@IoaNNUwU`` r? ``@joboet``
Location
rust/library/std/src/sync/mutex.rs
Lines 186 to 189 in 0ad927c
Summary
I think it is a good idea to document
Send
&Sync
impls in types such asMutex
,RwLock
etc. especially considering they areunsafe
traits.Also it's not obvious why some types have particular restrictions, for example:
Mutex
isSync
only if theT: Send
MutexGuard
is!Send
It can be done as // SAFETY comments or proper docs.
The text was updated successfully, but these errors were encountered: