Julio Biason
3 years ago
3 changed files with 47 additions and 0 deletions
@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
version = 3 |
||||
|
||||
[[package]] |
||||
name = "spmc" |
||||
version = "0.3.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" |
||||
|
||||
[[package]] |
||||
name = "spmctest" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"spmc", |
||||
] |
@ -0,0 +1,7 @@
|
||||
[package] |
||||
name = "spmctest" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
[dependencies] |
||||
spmc = "0.3" |
@ -0,0 +1,24 @@
|
||||
use std::thread; |
||||
|
||||
fn main() { |
||||
let (mut tx, rx) = spmc::channel(); |
||||
|
||||
let mut handles = Vec::new(); |
||||
for n in 0..5 { |
||||
let rx = rx.clone(); |
||||
handles.push(thread::spawn(move || { |
||||
while let Ok(msg) = rx.recv() { |
||||
// println!("Hello");
|
||||
println!("worker {} recvd: {}", n, msg); |
||||
} |
||||
})); |
||||
} |
||||
|
||||
for i in 0..15 { |
||||
tx.send(i).unwrap(); |
||||
} |
||||
|
||||
for handle in handles { |
||||
handle.join().unwrap(); |
||||
} |
||||
} |
Loading…
Reference in new issue