pub struct MpscFanIn;Expand description
Builder + handle factory for an N-producer fan-in. After construction,
move each MpscFanInProducer to its producing thread and the single
MpscFanInConsumer to its consuming thread.
Implementations§
Source§impl MpscFanIn
impl MpscFanIn
Sourcepub fn with_capacity<T: Send + 'static>(
producer_count: usize,
per_ring_capacity: usize,
) -> (Vec<MpscFanInProducer<T>>, MpscFanInConsumer<T>)
pub fn with_capacity<T: Send + 'static>( producer_count: usize, per_ring_capacity: usize, ) -> (Vec<MpscFanInProducer<T>>, MpscFanInConsumer<T>)
Build producer_count SPSC rings of capacity per_ring_capacity and
return matched producer / consumer handles.
Examples found in repository?
More examples
examples/sample_app.rs (line 187)
181fn many_venue_fan_in() {
182 use subms_spsc_ring_buffer::MpscFanIn;
183
184 println!("\n== mpsc-fan-in: three venue feeds -> one strategy ==");
185 let venues = 3usize;
186 let per_venue = 20_000u64;
187 let (mut producers, mut consumer) = MpscFanIn::with_capacity::<Tick>(venues, 256);
188
189 let mut feeds = Vec::new();
190 for venue in 0..venues {
191 let mut p = producers.remove(0);
192 feeds.push(thread::spawn(move || {
193 for seq in 0..per_venue {
194 let tick = Tick {
195 seq,
196 price_cents: 40_000 + venue as u32,
197 };
198 while p.try_push(tick).is_err() {
199 std::hint::spin_loop();
200 }
201 }
202 }));
203 }
204 let total = per_venue * venues as u64;
205 let strategy = thread::spawn(move || {
206 let mut got = 0u64;
207 while got < total {
208 if consumer.try_pop().is_some() {
209 got += 1;
210 }
211 }
212 got
213 });
214 for f in feeds {
215 f.join().unwrap();
216 }
217 let got = strategy.join().unwrap();
218 println!(" {venues} feeds x {per_venue} ticks -> consumer drained {got}");
219 assert_eq!(got, total);
220}Auto Trait Implementations§
impl Freeze for MpscFanIn
impl RefUnwindSafe for MpscFanIn
impl Send for MpscFanIn
impl Sync for MpscFanIn
impl Unpin for MpscFanIn
impl UnsafeUnpin for MpscFanIn
impl UnwindSafe for MpscFanIn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more