You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't think of a use case where this actually gives you any guarantees. You can still use it to protect another Sync data structure, but you can just as well forget to do so. One should always put the components that are protected into the Mutex even if not strictly necessary due to the componentes being thread safe themselves.
There is a use case for Mutex<()>. Consider that you have three Rust functions that wrap C functions provided by a non-reentrant C lib, so all three functions need to synchronize between themselves. They can do this by being inherent fns of a newtype struct CHandle(Mutex<()>);, since they do need a Mutex for unlock notifications, but there's nothing to guard inside the mutex.
Similarly if you many disparate types whose inherent fns are implemented in terms of the non-reentrant C library's functions, then multiple disparate values might end up sharing the same Arc<CHandle>.
But this does not detact from the lint proposal, since Mutex<()> misuse is definitely something to lint for. The cases I described can easily #[allow] the lint.
I can't think of a use case where this actually gives you any guarantees. You can still use it to protect another
Sync
data structure, but you can just as well forget to do so. One should always put the components that are protected into theMutex
even if not strictly necessary due to the componentes being thread safe themselves.An example of such a situation would be
where one should not modify the two values one by one, but always together in a single critical section.
The text was updated successfully, but these errors were encountered: