Curriculum Production Rust Threads and channels
Threads and channels
Rust's ownership rules extend into concurrency. This theme covers thread::spawn, move closures, JoinHandle, message passing with channels, and shared state with Arc<Mutex<T>>. Planned exercises: 1. choose move for spawned threads. 2. recognise join. 3. choose a channel for message passing. 4. fill thread::spawn. 5. fill Arc::clone. 6. write a thread that returns a value. 7. write a channel sender and receiver. 8. translate TS async-looking work into threaded Rust. 9. fix shared mutable state with Arc<Mutex<_>>.
Exercises
9 ready
01
pick one
A spawned thread needs to OWN its captured data — the parent
02
pick one
After let handle = thread::spawn(...), how do you BLOCK
03
pick one
Pick the standard library module that provides channels for
04
fill blanks
Fill the function that spawns a new OS thread running a
05
fill blanks
Fill the call that increments the reference count on an Arc
06
write a program
Spawn a thread that computes 21 * 2 and returns the result.
07
write a program
Create a channel. Spawn a thread that sends "hello" through
08
write a program
Translate Promise.all([double(1), double(2), double(3)]) to
09
write a program
Three threads each increment a shared counter. Without