-
Book Overview & Buying
-
Table Of Contents
The Rust Programming Handbook
By :
So far, we’ve seen how to share data between threads using Arc for shared ownership and Mutex or RwLock for synchronizing access to mutable data. This is often called shared-state concurrency. While powerful, managing locks and shared memory can sometimes be complex and prone to issues such as deadlocks if not handled carefully.
Rust, like many modern languages, also offers another excellent model for concurrency: message passing. The core idea here is: “Do not communicate by sharing memory; instead, share memory by communicating.” Threads send messages to each other over channels, transferring data ownership without needing complex locking mechanisms on the data itself.
Instead of multiple threads trying to access and modify the same piece of memory (protected by locks), message passing involves one thread sending a piece of data to another thread. Once the data...