Trait embassy_sync::blocking_mutex::raw::RawMutex
source · pub unsafe trait RawMutex {
const INIT: Self;
// Required method
fn lock<R>(&self, f: impl FnOnce() -> R) -> R;
}
Expand description
Raw mutex trait.
This mutex is “raw”, which means it does not actually contain the protected data, it
just implements the mutex mechanism. For most uses you should use super::Mutex
instead,
which is generic over a RawMutex and contains the protected data.
Note that, unlike other mutexes, implementations only guarantee no concurrent access from other threads: concurrent access from the current thread is allowed. For example, it’s possible to lock the same mutex multiple times reentrantly.
Therefore, locking a RawMutex
is only enough to guarantee safe shared (&
) access
to the data, it is not enough to guarantee exclusive (&mut
) access.
§Safety
RawMutex implementations must ensure that, while locked, no other thread can lock the RawMutex concurrently.
Unsafe code is allowed to rely on this fact, so incorrect implementations will cause undefined behavior.