Debian Codegraph @

.cargo/vendor/rustfft/examples/concurrency.rs

raw
1 //! Show how to use an `FFT` object from multiple threads
2
3 use std::sync::Arc;
4 use std::thread;
5
6 use rustfft::num_complex::Complex32;
7 use rustfft::FftPlanner;
8
9 fn main() {
10 let mut planner = FftPlanner::new();
11 let fft = planner.plan_fft_forward(100);
12
13 let threads: Vec<thread::JoinHandle<_>> = (0..2)
14 .map(|_| {
15 let fft_copy = Arc::clone(&fft);
16 thread::spawn(move || {
17 let mut buffer = vec![Complex32::new(0.0, 0.0); 100];
18 fft_copy.process(&mut buffer);
19 })
20 })
21 .collect();
22
23 for thread in threads {
24 thread.join().unwrap();
25 }
26 }