Last active: a year ago
thread_channel.rs
use std::sync::mpsc;
use std::thread;
fn main() {
let cores = num_cpus::get();
let (tx, rx) = mpsc::channel();
(0..cores).for_each(|core| {
let tx = tx.clone();
thread::spawn(move || {
if let Err(e) = tx.send(core) {
println!("Get error: {e}")
}
});
});
drop(tx);
for received in rx {
println!("Get value from thread: {received}")
}
}