pub unsafe trait Lock {
// Required methods
fn lock(&self);
fn unlock(&self);
}Expand description
A trait for providing mutual exclusion.
If you do not need to use the allocator, and collections using it, in a
multi-threaded environment, you may use SingleThreadedLock, which is the
moral equivalent of a RefCell.
§Safety
-
If the implementation type is
Sync, then an allocator using this locking mechanism will beSync, and therefore this method must provide actual mutual exclusion and prevent against unsynchronized accesses. -
Even in single-threaded contexts, where real synchronization is not required, this type must prevent recursive locking and re-entering the lock when it is already held. The prevention may be a panic, abort, infinite loop, or etc…