Skip to main content

set_thread_priority_and_policy

Function set_thread_priority_and_policy 

pub fn set_thread_priority_and_policy(
    native: u64,
    priority: ThreadPriority,
    policy: ThreadSchedulePolicy,
) -> Result<(), Error>
Available on Linux or macOS or iOS or DragonFly BSD or FreeBSD or OpenBSD or VxWorks or NetBSD or Android or WebAssembly only.
Expand description

Sets thread’s priority and schedule policy

  • May require privileges

§Usage

Setting thread priority to minimum with normal schedule policy:

use thread_priority::*;

let thread_id = thread_native_id();
assert!(set_thread_priority_and_policy(thread_id,
                                       ThreadPriority::Min,
                                       ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo)).is_ok());

§Note

In case the value is specified as ThreadPriority::Crossplatform and is incompatible with the policy, an error is returned. However if ThreadPriority::Min or ThreadPriority::Max are used, the correct value is used automatically according to the range of the policy’s allowed values.