mpsc-full
cargo devel CI / cargo CI (push) Successful in 1m26s Details

This commit is contained in:
Christoph J. Scherr 2024-03-04 12:17:55 +01:00
parent 2a2dc41446
commit d804f5b2a6
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
4 changed files with 49 additions and 0 deletions

7
Cargo.lock generated
View File

@ -897,6 +897,13 @@ dependencies = [
"anyhow",
]
[[package]]
name = "mpsc-full"
version = "0.1.0"
dependencies = [
"anyhow",
]
[[package]]
name = "nom"
version = "7.1.3"

View File

@ -15,11 +15,13 @@ members = [
"members/matchmatchmatch",
"members/future_stream",
"members/mpsc",
"members/mpsc-full",
]
default-members = [
".",
"members/revsqrt",
"members/mpsc",
"members/mpsc-full",
"members/criterion-demo",
"members/shortc",
"members/pest-demo",

View File

@ -0,0 +1,9 @@
[package]
name = "mpsc-full"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow.workspace = true

View File

@ -0,0 +1,31 @@
//! what happens when we send a lot of items to an mpsc?
use std::{
sync::{mpsc, Barrier},
thread,
};
const NUMS: &[u8] = &[1, 3, 3, 7, 0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf];
fn main() -> anyhow::Result<()> {
let (sender, receiver) = mpsc::channel();
for n in NUMS {
sender.send(n).unwrap();
}
drop(sender);
let mut collect = Vec::new();
while let Ok(n) = receiver.recv() {
collect.push(*n);
}
for i in NUMS {
assert!(collect.contains(i))
}
println!("it stores the values, even when the sender is dropped");
Ok(())
}