Mutex<u32>
for the counterCondvar
for wait operations to wait forpark
unpark
Note how a mutex can be implemented using a semaphore, while a semaphore can be implemented using a mutex (and a condition variable). It’s advisable to avoid using a mutex-based semaphore to implement a semaphore-based mutex, and the other way around.
compare_exchange
)(MP => master processor)
std::thread::Thread
object.Mutex
RwLock
Condvar
Barrier
Once
ReentrantMutex
(supports recursive locking)blog post by Alex Bradbury earlier this week
parking_lot
Rust crate.Mutex
RwLock
Condvar
Once
SeqLock
type, which is a form of reader-writer lock that is heavily optimized for readers.SeqLock
can be two orders of magnitude faster than the standard library RwLock
type. Another advantage is that readers cannot starve writers: a writer will never block even if there are readers currently accessing the SeqLock
.SeqLock
is that it only works on types that are Copy
. This means that it is unsuitable for types that contains pointers to owned data.RwLock
if you need a reader-writer lock for types that are not Copy
.use seqlock::SeqLock;
let lock = SeqLock::new(5);
{
// Writing to the data involves a lock
let mut w = lock.lock_write();
*w += 1;
assert_eq!(*w, 6);
}
{
// Reading the data is a very fast operation
let r = lock.read();
assert_eq!(r, 6);
}