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
Replay: real traced execution (multi-file project)
use std::sync::mpsc::sync_channel;
fn main() {
let capacity = 2;
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 = 0;
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 = 4;
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}");
}
capacity ← 2, messages ← 3, sent ← 0, rejected ← 0
3fn main() {4 let capacit→ 2y = 2; //@capacity=2, 4, 05 let message→ 3s = 3;6 let (tx, _rx) = sync_channel(capacit2y);7 let mut sen→ 0t = 0;8 let mut rejecte→ 0d = 0;9 for value in 0..messages {for value in 0..messages
pass 1 of 38let mut rejected = 0;9for valu0e in 0..message3s {10 match tx.try_send(value) {All 3 passes — pass 1 is the card above pass value1 0 2 1 3 2 status ← "partial"
14 }15 let statu→ "partial"s = if rejecte1d == 0 {16 "buffered"17 } else if sen2t == 0 {18 "saturated"19 } else {20 "partial"21 };22 println!("capacity={capacity} sent={sent} rejected={rejected} {status}");23}outputcapacity=2 sent=2 rejected=1 partial
capacity ← 0, messages ← 3, sent ← 0, rejected ← 0
3fn main() {4 let capacit→ 0y = 0;5 let message→ 3s = 3;6 let (tx, _rx) = sync_channel(capacit0y);7 let mut sen→ 0t = 0;8 let mut rejecte→ 0d = 0;9 for value in 0..messages {for value in 0..messages
pass 1 of 38let mut rejected = 0;9for valu0e in 0..message3s {10 match tx.try_send(value) {All 3 passes — pass 1 is the card above pass value1 0 2 1 3 2 status ← "saturated"
14 }15 let statu→ "saturated"s = if rejecte3d == 0 {16 "buffered"17 } else if sen0t == 0 {18 "saturated"19 } else {20 "partial"21 };22 println!("capacity={capacity} sent={sent} rejected={rejected} {status}");23}outputcapacity=0 sent=0 rejected=3 saturated
capacity ← 4, messages ← 3, sent ← 0, rejected ← 0
3fn main() {4 let capacit→ 4y = 4;5 let message→ 3s = 3;6 let (tx, _rx) = sync_channel(capacit4y);7 let mut sen→ 0t = 0;8 let mut rejecte→ 0d = 0;9 for value in 0..messages {for value in 0..messages
pass 1 of 38let mut rejected = 0;9for valu0e in 0..message3s {10 match tx.try_send(value) {All 3 passes — pass 1 is the card above pass value1 0 2 1 3 2 status ← "buffered"
14 }15 let statu→ "buffered"s = if rejecte0d == 0 {16 "buffered"17 } else if sen3t == 0 {18 "saturated"19 } else {20 "partial"21 };22 println!("capacity={capacity} sent={sent} rejected={rejected} {status}");23}outputcapacity=4 sent=3 rejected=0 buffered
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.