Module 7Threads & ChannelsLesson 1 of 720 min
Threads Basics
spawn, join, and move closures.
Spawn work
rust
use std::thread;
let h = thread::spawn(|| { 42 });
let v = h.join().unwrap();move closures
Threads often need move to take ownership of captured data.
Quant angle
Each thread can price a chunk of Monte Carlo paths.
Challenge
Change to sum of squares per chunk.
Tips
- join waits for thread
- move transfers ownership
- Map chunks for data parallelism
Try it live
Threads BasicsRust 2021
Loading editor…
Output
Press Run to compile and execute.