File: concurrency.rs

package info (click to toggle)
rust-rustfft 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,104 kB
  • sloc: python: 309; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 670 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! Show how to use an `FFT` object from multiple threads

use std::sync::Arc;
use std::thread;

use rustfft::num_complex::Complex32;
use rustfft::FftPlanner;

fn main() {
    let mut planner = FftPlanner::new();
    let fft = planner.plan_fft_forward(100);

    let threads: Vec<thread::JoinHandle<_>> = (0..2)
        .map(|_| {
            let fft_copy = Arc::clone(&fft);
            thread::spawn(move || {
                let mut buffer = vec![Complex32::new(0.0, 0.0); 100];
                fft_copy.process(&mut buffer);
            })
        })
        .collect();

    for thread in threads {
        thread.join().unwrap();
    }
}