-
-
Save rust-play/cded84554988bb219c26a89d52246133 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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