#thread #real-time

audio_thread_priority

Bump a thread to real-time priority, for audio work, on Linux, Windows and macOS

42 releases (breaking)

0.31.0 Jan 17, 2024
0.30.0 Nov 6, 2023
0.29.0 Nov 2, 2023
0.27.1 Mar 30, 2023
0.3.0 Jan 25, 2018

#92 in Audio

Download history 551/week @ 2023-11-11 358/week @ 2023-11-18 389/week @ 2023-11-25 246/week @ 2023-12-02 259/week @ 2023-12-09 278/week @ 2023-12-16 253/week @ 2023-12-23 275/week @ 2023-12-30 530/week @ 2024-01-06 544/week @ 2024-01-13 497/week @ 2024-01-20 598/week @ 2024-01-27 557/week @ 2024-02-03 471/week @ 2024-02-10 720/week @ 2024-02-17 400/week @ 2024-02-24

2,226 downloads per month
Used in audir

MPL-2.0 license

51KB
918 lines

audio_thread_priority

Synopsis:


use audio_thread_priority::{promote_current_thread_to_real_time, demote_current_thread_from_real_time};

// ... on a thread that will compute audio and has to be real-time:
match promote_current_thread_to_real_time(512, 44100) {
  Ok(h) => {
    println!("this thread is now bumped to real-time priority.");

    // Do some real-time work...

    match demote_current_thread_from_real_time(h) {
      Ok(_) => {
        println!("this thread is now bumped back to normal.")
      }
      Err(_) => {
        println!("Could not bring the thread back to normal priority.")
      }
    };
  }
  Err(e) => {
    eprintln!("Error promoting thread to real-time: {}", e);
  }
}

This library can also be used from C or C++ using the included header and compiling the rust code in the application. By default, a .a is compiled to ease linking.

License

MPL-2

Dependencies

~0–11MB
~96K SLoC