qos-threads
Cross-platform Quality-of-Service controls for native threads and processes.
Platform support
| Target | Behavior |
|---|---|
| macOS | Native per-thread QoS and process disk-I/O controls |
| Linux and Android | Native per-thread nice-level controls; process I/O is delegated to the service manager |
| Windows and other targets | Compiles with successful no-op scheduling controls |
The crate is therefore useful on every target as a stable API, but it only changes operating-system scheduling natively on macOS, Linux, and Android.
This crate provides a small platform abstraction for workloads that share a machine but have different scheduling needs:
Qos::High— latency-sensitive work that should remain responsive under load. On macOS this maps toQOS_CLASS_USER_INITIATED; on Linux it maps to the normal nice level.Qos::Low— background or CPU-bound work that should yield to interactive workloads. On macOS this maps toQOS_CLASS_UTILITY; on Linux it maps to a positive nice level.
Thread controls
Use set_current_thread from a thread-pool startup hook when a thread keeps
the same scheduling class for its lifetime:
use ;
set_current_thread?;
# Ok::
Use with_qos when a reused thread needs a temporary class. The previous
class is restored even when the closure unwinds:
use ;
let answer = with_qos;
assert_eq!;
Process I/O
boost_process_io raises the process's disk-I/O policy where the operating
system provides such a control. This is useful when durable I/O should not be
treated as background housekeeping. On platforms where the process-level
policy is managed by the service manager, the function is a successful no-op.
Platform behavior
The API is intentionally small and platform-neutral. Unsupported platforms
return success without changing scheduling, while an operating-system
rejection is returned as QosError. Callers can decide whether a scheduling
policy is advisory or mandatory for their workload.
The crate currently implements native controls for Apple platforms and Linux or Android. Other platforms compile with the documented no-op behavior.
License
Licensed under either of:
at your option.