Julio Biason
2 years ago
3 changed files with 46 additions and 0 deletions
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
version = 3 |
||||
|
||||
[[package]] |
||||
name = "prodconrs" |
||||
version = "0.1.0" |
@ -0,0 +1,8 @@
|
||||
[package] |
||||
name = "prodconrs" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
@ -0,0 +1,31 @@
|
||||
use std::sync::mpsc; |
||||
use std::thread; |
||||
|
||||
fn main() { |
||||
let (tx, rx) = mpsc::channel(); |
||||
let self_tx = tx.clone(); |
||||
|
||||
let consumer = thread::spawn(move || { |
||||
while let Ok(msg) = rx.recv() { |
||||
if msg == 0 { |
||||
println!("Quit"); |
||||
break; |
||||
} |
||||
|
||||
println!("Message: {}", msg); |
||||
} |
||||
}); |
||||
|
||||
let producer = thread::spawn(move || { |
||||
for i in 1..12 { |
||||
tx.send(i); |
||||
} |
||||
tx.send(0); |
||||
}); |
||||
|
||||
println!("Waiting producer..."); |
||||
producer.join(); |
||||
println!("Waiting consumer..."); |
||||
consumer.join(); |
||||
|
||||
} |
Loading…
Reference in new issue