Concurrency
This section covers concurrent and parallel programming.
Recipe | Crates | Categories |
---|---|---|
Spawn, join | ||
Scoped threads | ||
Rayon - parallel processing | ||
Parallel iteration | ||
Parallel sorting | ||
Custom parallel tasks |
TODO
TODO
TODO
Recipe | Crates | Categories |
---|---|---|
Multiple producers, single consumer | ||
Crossbeam_channel |
TODO
Parallelism
-
True simultaneous execution of multiple tasks on multiple cores or processors.
-
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.
Here are the topics we’ll cover: