Concurrency Coordination Reports
Sync Channel Capacity Coordination Report
A capacity report records how a bounded channel handles offered messages. This program uses sync_channel with try_send and reports buffered versus rejected sends for the selected capacity.
Program
Play the program to choose the channel capacity and watch how many sends are buffered or rejected.
sync_channel_capacity_coordination_report.rs
use std::sync::mpsc::sync_channel;
fn main() {
let capacity = ;
let messages = 3;
let (tx, _rx) = sync_channel(capacity);
let mut sent = 0;
let mut rejected = 0;
for value in 0..messages {
match tx.try_send(value) {
Ok(()) => sent += 1,
Err(_) => rejected += 1,
}
}
let status = if rejected == 0 {
"buffered"
} else if sent == 0 {
"saturated"
} else {
"partial"
};
println!("capacity={capacity} sent={sent} rejected={rejected} {status}");
}
use std::sync::mpsc::sync_channel;
fn main() {
let capacity = ;
let messages = 3;
let (tx, _rx) = sync_channel(capacity);
let mut sent = 0;
let mut rejected = 0;
for value in 0..messages {
match tx.try_send(value) {
Ok(()) => sent += 1,
Err(_) => rejected += 1,
}
}
let status = if rejected == 0 {
"buffered"
} else if sent == 0 {
"saturated"
} else {
"partial"
};
println!("capacity={capacity} sent={sent} rejected={rejected} {status}");
}
use std::sync::mpsc::sync_channel;
fn main() {
let capacity = ;
let messages = 3;
let (tx, _rx) = sync_channel(capacity);
let mut sent = 0;
let mut rejected = 0;
for value in 0..messages {
match tx.try_send(value) {
Ok(()) => sent += 1,
Err(_) => rejected += 1,
}
}
let status = if rejected == 0 {
"buffered"
} else if sent == 0 {
"saturated"
} else {
"partial"
};
println!("capacity={capacity} sent={sent} rejected={rejected} {status}");
}
bounded buffer
`sync_channel` creates a bounded queue, so `try_send` reports `Ok` only while buffer space remains.
capacity report
The selected capacity controls how many messages are buffered before `try_send` is rejected.
rendezvous
A zero-capacity channel has no buffer, so every `try_send` without a waiting receiver is rejected and the report saturates.