We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Fearless Concurrency: Threads, Channels, Shared State
RustCoordinate threads with channels, shared ownership and locks. Practise scoped threads, handle worker failures, and recognize deadlock risks.
This track uses Rust. You can make it your practice mode to browse related content across the site.
Your learning sequence
- 1 Not solved yet. Threads, spawn and join Practice · Easy
- 2 Not solved yet. move closures: why the compiler forces your hand Practice · Easy
- 3 Not solved yet. JoinHandle, panics and thread::Result Practice · Medium
- 4 Not solved yet. Scoped threads: borrow, do not clone Practice · Easy
- 5 Not solved yet. Balanced ranges: the arithmetic before the threads Practice · Easy
- 6 Not solved yet. Send: what it actually guarantees Practice · Medium
- 7 Not solved yet. Sync: T is Sync exactly when &T is Send Practice · Medium
- 8 Not solved yet. unsafe impl Send, and the disjoint-capture trap Practice · Hard
- 9 Not solved yet. Arc: shared ownership across threads Practice · Easy
- 10 Not solved yet. Share a mutable vector with Arc and Mutex Practice · Easy
- 11 Not solved yet. Mutex and MutexGuard: unlocking with RAII Practice · Easy
- 12 Not solved yet. Release a read guard before acquiring a write lock Practice · Hard
- 13 Not solved yet. Poisoning: what a panic does to a lock Practice · Medium
- 14 Not solved yet. Keep worker-pool results in input order Practice · Medium
- 15 Not solved yet. Prevent deadlocks with consistent lock ordering Practice · Hard
- 16 Not solved yet. mpsc channels: message passing basics Practice · Easy
- 17 Not solved yet. Let a channel receiver finish by dropping its senders Practice · Medium
- 18 Not solved yet. sync_channel: bounded buffers and backpressure Practice · Medium
- 19 Not solved yet. Coordinate two threads with a condition variable Practice · Hard
- 20 Not solved yet. Safe parallel mutation with chunks_mut Practice · Medium
- 21 Not solved yet. Barrier: keeping workers in lock step Practice · Medium
- 22 Not solved yet. park and unpark: building a blocking primitive by hand Practice · Hard
- 23 Choosing your concurrency primitive Read
- 24 Reduce deadlock risks in shared-state code Read
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
Why does the main thread drop its original sender before collecting messages?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
let mut workers = Vec::new();
for i in 0..3 {
let sender = tx.clone();
workers.push(thread::spawn(move || sender.send(i * 10).unwrap()));
}
drop(tx);
let mut values: Vec<_> = rx.iter().collect();
for worker in workers {
worker.join().unwrap();
}
values.sort_unstable();
println!("{values:?}");
}