Concurrency in Rust
Instructor: Martin Geisler
As modern CPUs get more and more cores, the ability to make efficient use of them becomes more and more important. Rust is uniquely suited to do this because of how its borrow checker prevents a wide range of problems in concurrent programs. This feature of Rust is often called fearless concurrency.
This workshop will show you how Rust enables you to do safe concurrent programming. We will talk about thread-based concurrency as well as the async/await style concurrency.
The Concurrency in Rust material is taken from the freely available Comprehensive Rust family of Rust courses.
Target Audience
This is an advanced class which assumes that you are already familiar with basic Rust. Concepts like borrowing, generics, and closures should be familiar to you. If you work through the material for Rust Fundamentals, then you will be up to speed.
Prerequisites
The workshop assumes that you have a functioning Rust setup with your favorite editor configured for Rust development. To prepare for the workshop, please also go through the following steps:
- Create a fresh project:
cargo init concurrency
. - Add Tokio as a dependency:
cargo add tokio --features full
- Compile the code at least once:
cargo run
This will save you some time since there are many dependencies to download and compile.
You can then copy/paste the examples into src/main.rs
to experiment with them
during the workshop.
Topics
The workshop is split in two parts: thread-based and async/await-based concurrency.
Morning: Multi-threaded Rust
In the morning, we will cover how to use threads in Rust:
- Threads and scoped threads.
- Safe communication between threads using channels.
- The
Send
andSync
traits - Shared state with reference counts and mutexes — fearless concurrency!
- Exercises: Dining Philosophers and an multi-threaded link checker.
The morning session will take approximately 3 hours.
Afternoon: Async Rust
In the afternoon, we will cover concurrency with async Rust:
- Basics of async Rust:
async
/await
. - Futures and async runtimes (Tokio).
- Control flow:
Join
andSelect
. - Pitfalls of async Rust: blocking calls,
Pin
, async traits, cancellation. - Exercises: Dining Philosophers again, broadcast chat app.
The afternoon session will take approximately 3 hours.
The workshop can fit 16 people.
For location and schedule visit our Workshops page