Browse Source

Testing spmc

master
Julio Biason 2 years ago
parent
commit
8edf368958
  1. 16
      spmc-test/Cargo.lock
  2. 7
      spmc-test/Cargo.toml
  3. 24
      spmc-test/src/main.rs

16
spmc-test/Cargo.lock generated

@ -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",
]

7
spmc-test/Cargo.toml

@ -0,0 +1,7 @@
[package]
name = "spmctest"
version = "0.1.0"
edition = "2021"
[dependencies]
spmc = "0.3"

24
spmc-test/src/main.rs

@ -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…
Cancel
Save