January 2019
Beginner to intermediate
554 pages
13h 31m
English
thread-safety is the property of a type or a piece of code that, when executed or accessed by multiple threads, does not lead to unexpected behavior. It refers to the idea that data is consistent for reads while being safe from corruption when multiple threads write to it.
Rust only protects you from data races. It doesn't aim to protect against deadlocks as they are difficult to detect. It instead offloads this to third-party crates such as the parking_lot crate.
Rust has a novel approach to protecting against data races. Most of the thread-safety bits are already embedded in the spawn method's type signature. Let's look at its type signature:
fn spawn<F, T>(f: F) -> JoinHandle<T> where F: FnOnce() -> T, F: Send + ...
Read now
Unlock full access