1 unstable release
Uses old Rust 2015
0.3.0 | Aug 16, 2019 |
---|---|
0.2.3 |
|
0.2.2 |
|
0.2.1 |
|
0.1.0 |
|
10,680 downloads per month
Used in 42 crates
(26 directly)
17KB
390 lines
spmc
Single-Producer, Multiple-Consumer channel for Rust.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
SPMC
A single producer, multiple consumers. Commonly used to implement work-stealing.
Example
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 || {
let msg = rx.recv().unwrap();
println!("worker {} recvd: {}", n, msg);
}));
}
for i in 0..5 {
tx.send(i * 2).unwrap();
}
for handle in handles {
handle.join().unwrap();
}