Mutex<T> and RwLock<T>
In this lesson, you will learn about `Mutex<T>` and `RwLock<T>`.
What is Mutex<T>
?
Mutex
stands for mutual exclusion. Unlike Cell
and RefCell
, Mutex
are thread-safe meaning it can be used with multiple threads safely, It does so by providing exclusive lock. By having an exclusive lock, Rust ensures that only one thread can change the data at any given time hence avoiding data races.
The data can be only accessed via lock
and try_lock
which ensures that the data is only accessed when the mutex is locked.
Poisoning
Mutex
uses a concept called poisoning where it is considered poisoned when a thread panics while holding the mutex. If the Mutex
has been poisoned then all ...
Access this course and 1400+ top-rated courses and projects.