Open
Description
struct MutexGuard<'a, T: 'a> {
data: &'a T,
//..
}
// Locking the mutex is explicit.
impl<T> Mutex<T> {
fn lock(&self) -> MutexGuard<T> {
// Lock the underlying OS mutex.
//..
// MutexGuard keeps a reference to self
MutexGuard {
data: self,
//..
}
}
}
Some of the code implies that MutexGuard references Mutex, but some other places imply that MutexGuard references T directly.
I believe the correct definition of MutexGuard 1 is
struct MutexGuard<'a, T: 'a> {
data: &'a Mutex<T>,
//..
}
And if MutexGuard contains a reference to Mutex rather than T, then the Deref
implementation needs to be corrected as well.
Footnotes
-
alternatively:
define lock asfn lock(&self) -> MutexGuard<Mutex<T>>
or change the creation of the MutexGuard toMutexGuard { data: self.<unnamed field for now, ... }
↩
Metadata
Metadata
Assignees
Labels
No labels