All Projects → vityafx → thread-priority

vityafx / thread-priority

Licence: MIT license
A simple thread schedule and priority library for rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to thread-priority

Advanced-xv6
Modern improvements for MIT's xv6 OS
Stars: ✭ 26 (-45.83%)
Mutual labels:  schedule, priority
ArmorLib
Easily scan files for threats to security and privacy. A Rust library and command line tool. WIP.
Stars: ✭ 20 (-58.33%)
Mutual labels:  rust-library
async cron
crontab for python,with asyncio
Stars: ✭ 23 (-52.08%)
Mutual labels:  schedule
inline-c-rs
Write and execute C code inside Rust.
Stars: ✭ 121 (+152.08%)
Mutual labels:  rust-library
cpp-thread-study
C++ 线程库示例及教程
Stars: ✭ 38 (-20.83%)
Mutual labels:  thread
kul
A unique textual notation that can be used as both a data format and a markup language and that has powerful extensibility of both lexical syntax and semantics, and a Rust library for parsing it.
Stars: ✭ 12 (-75%)
Mutual labels:  rust-library
otp
One Time Password for 2-Factor-Authentication implemented in Rust
Stars: ✭ 21 (-56.25%)
Mutual labels:  rust-library
healthchecks-rs
Simple Rust library to interact with healthchecks.io
Stars: ✭ 16 (-66.67%)
Mutual labels:  rust-library
daemonize-me
Rust library to ease the task of creating daemons
Stars: ✭ 34 (-29.17%)
Mutual labels:  rust-library
dupe-krill
A fast file deduplicator
Stars: ✭ 147 (+206.25%)
Mutual labels:  rust-library
RxSchedulerSuppress
RxSchedulerSuppress 是用于抑制 RxJava 在同一个线程池内重复调度的工具
Stars: ✭ 30 (-37.5%)
Mutual labels:  thread
betterdocs
📚 Web version of https://github.com/khusnetdinov/ruby.fundamental repo - Fundamental programming with ruby examples and references. It covers threads, SOLID principles, design patterns, data structures, algorithms. Books for reading.
Stars: ✭ 25 (-47.92%)
Mutual labels:  thread
version-compare
↔️ Rust library to easily compare version strings. Mirror from https://gitlab.com/timvisee/version-compare
Stars: ✭ 32 (-33.33%)
Mutual labels:  rust-library
rust-cross-libs
Cross-compile the Rust standard library for custom targets without a full bootstrap build.
Stars: ✭ 29 (-39.58%)
Mutual labels:  rust-library
tape-recorder
BSV Hackathon: Use Tape Recorder to record any computation onto Bitcoin Script using a Wang B machine written in Forth
Stars: ✭ 22 (-54.17%)
Mutual labels:  thread
mpris-rs
Idiomatic MPRIS D-Bus interface library for Rust
Stars: ✭ 37 (-22.92%)
Mutual labels:  rust-library
rspark
▁▂▆▇▁▄█▁ Sparklines for Rust apps
Stars: ✭ 50 (+4.17%)
Mutual labels:  rust-library
Adun
A way to backdoor every process
Stars: ✭ 58 (+20.83%)
Mutual labels:  thread
unicode-linebreak
󠁼💔 Implementation of the Unicode Line Breaking Algorithm in Rust
Stars: ✭ 14 (-70.83%)
Mutual labels:  rust-library
TSNsched
Automated Schedule Generation for Time-Sensitive Networks (TSN).
Stars: ✭ 46 (-4.17%)
Mutual labels:  schedule

thread-priority

CI Crates Docs MIT licensed

A simple library to control thread schedule policies and thread priority.

If your operating system isn't yet supported, please, create an issue.

Minimal Rust Compiler Version

Is 1.46. If you need any help making it possible to compile with 1.36 please reach out.

Supported platforms

  • Linux
  • Android
  • DragonFly
  • FreeBSD
  • OpenBSD
  • NetBSD
  • macOS
  • Windows

Examples

Minimal cross-platform examples

Setting current thread's priority to minimum:

use thread_priority::*;

fn main() {
    assert!(set_current_thread_priority(ThreadPriority::Min).is_ok());
}

The same as above but using a specific value:

use thread_priority::*;
use std::convert::TryInto;

fn main() {
    // The lower the number the lower the priority.
    assert!(set_current_thread_priority(ThreadPriority::Crossplatform(0.try_into().unwrap())).is_ok());
}

Windows-specific examples

Set the thread priority to the lowest possible value:

use thread_priority::*;

fn main() {
    // The lower the number the lower the priority.
    assert!(set_current_thread_priority(ThreadPriority::Os(WinAPIThreadPriority::Lowest.into())).is_ok());
}

Set the ideal processor for the new thread:

use thread_priority::*;

fn main() {
    std::thread::spawn(|| {
        set_thread_ideal_processor(thread_native_id(), 0);
        println!("Hello world!");
    });
}

Building a thread using the ThreadBuilderExt trait

use thread_priority::*;
use thread_priority::ThreadBuilderExt;

let thread = std::thread::Builder::new()
    .name("MyNewThread".to_owned())
    .spawn_with_priority(ThreadPriority::Max, |result| {
        // This is printed out from within the spawned thread.
        println!("Set priority result: {:?}", result);
        assert!(result.is_ok());
}).unwrap();
thread.join();

Building a thread using the ThreadBuilder.

use thread_priority::*;

let thread = ThreadBuilder::default()
    .name("MyThread")
    .priority(ThreadPriority::Max)
    .spawn(|result| {
        // This is printed out from within the spawned thread.
        println!("Set priority result: {:?}", result);
        assert!(result.is_ok());
}).unwrap();
thread.join();

// Another example where we don't care about the priority having been set.
let thread = ThreadBuilder::default()
    .name("MyThread")
    .priority(ThreadPriority::Max)
    .spawn_careless(|| {
        // This is printed out from within the spawned thread.
        println!("We don't care about the priority result.");
}).unwrap();
thread.join();

Using ThreadExt trait on the current thread

use thread_priority::*;

assert!(std::thread::current().get_priority().is_ok());
println!("This thread's native id is: {:?}", std::thread::current().get_native_id());

License

This project is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].