How would I set a thread priority in Rust in macOS?

Viewed 187

The crate thread-priority is only supported on Windows and Linux operating systems but unfortunately isn't supported for macOS. So the only crate I found that would support macOS was libc but it lacks documentation

The application I'm making needs global key press events which has to be reliable and time sensitive, so to test the application in development, I used sudo nice -n -20 cargo run and the difference was clear that the code I tried for libc crate wasn't working.

This is the code I tried for libc:

fn main() {
  unsafe {
     libc::setpriority(libc::PRIO_PROCESS, 0, -20);
  }
}

Someone suggested me this for macOS in a Rust Discord Server which unfortunately didn't make any difference as well:

fn main() {
  unsafe {
     libc::setpriority(libc::PRIO_DARWIN_THREAD, 0, -20);
  }
}

Edit: As I would be publishing this CLI in Homebrew, a command without sudo is required to make it not suspicious to people installing it.

0 Answers
Related