-
-
Save se1983/6f0b48fe45a186ed8b0d4f83866feacd to your computer and use it in GitHub Desktop.
Channels between two threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::sync::mpsc; | |
fn main() { | |
let (tx, rx) = mpsc::channel(); | |
let h1 = thread::spawn(move || { | |
let val = String::from("hi"); | |
tx.send(val).unwrap(); | |
}); | |
let h2 = thread::spawn(move || { | |
let val = rx.recv().unwrap(); | |
println!("{}", val); | |
}); | |
h1.join().unwrap(); | |
h2.join().unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment