Skip to content

Instantly share code, notes, and snippets.

@se1983
Forked from rust-play/playground.rs
Last active April 19, 2020 06:39
Show Gist options
  • Save se1983/6f0b48fe45a186ed8b0d4f83866feacd to your computer and use it in GitHub Desktop.
Save se1983/6f0b48fe45a186ed8b0d4f83866feacd to your computer and use it in GitHub Desktop.
Channels between two threads
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