Lesson 36 of 50 · rust
Channels and Message Passing
Duration: 15 minutes
Lesson 36 of 50 · rust
Duration: 15 minutes
std::sync::mpsc provides multi‑producer, single‑consumer channels.\n\nrust\nuse std::sync::mpsc;\nuse std::thread;\n\nfn main() {\n let (tx, rx) = mpsc::channel();\n thread::spawn(move || {\n let data = \"Hello from thread\";\n tx.send(data).unwrap();\n });\n let received = rx.recv().unwrap();\n println!(\"Received: {}\", received);\n}\n\n