#real-time #thread #priority #bump #applications #promote

audio_thread_priority

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

43 releases (breaking)

0.32.0 Mar 14, 2024
0.30.0 Nov 6, 2023
0.27.1 Mar 30, 2023
0.26.1 Mar 22, 2022
0.3.0 Jan 25, 2018

#70 in Audio

Download history 793/week @ 2024-07-26 684/week @ 2024-08-02 616/week @ 2024-08-09 771/week @ 2024-08-16 876/week @ 2024-08-23 469/week @ 2024-08-30 641/week @ 2024-09-06 1168/week @ 2024-09-13 917/week @ 2024-09-20 480/week @ 2024-09-27 690/week @ 2024-10-04 755/week @ 2024-10-11 525/week @ 2024-10-18 519/week @ 2024-10-25 550/week @ 2024-11-01 447/week @ 2024-11-08

2,201 downloads per month
Used in audir

MPL-2.0 license

56KB
1K SLoC

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–9MB
~83K SLoC