This section covers concurrent programming, and specifically parallel programming.
Parallelism implies:
- True simultaneous execution of multiple tasks on multiple cores or processors.
- Mechanism: uses operating system threads.
- Important for CPU-heavy computations.
- Often requires explicit management of threads and thread pools.
- Requires careful synchronization to prevent data races (using mechanisms like mutexes or atomics).
- Overhead due to thread creation and switching.
Key constructs in Rust:
- Threads are independent units of execution that can be spawned using e.g.
std::thread::spawn
.
- Mutexes e.g.
std::sync::Mutex
protect shared data from race conditions.
- Channels e.g.
std::sync::mpsc
allow threads to communicate and exchange data.
⮳
[concurrency: add somewhere [Rust Atomics][book-rust-atomics] (P1)](https://github.com/john-cd/rust_howto/issues/263)root@1f41c0391f7d:/code#