pub trait ThreadExt {
// Required method
fn get_native_id(&self) -> Result<ThreadId, Error>;
// Provided methods
fn get_priority(&self) -> Result<ThreadPriority, Error> { ... }
fn set_priority(&self, priority: ThreadPriority) -> Result<(), Error> { ... }
fn get_schedule_policy(&self) -> Result<ThreadSchedulePolicy, Error> { ... }
fn get_schedule_policy_param(
&self,
) -> Result<(ThreadSchedulePolicy, ScheduleParams), Error> { ... }
fn set_priority_and_policy(
&self,
policy: ThreadSchedulePolicy,
priority: ThreadPriority,
) -> Result<(), Error> { ... }
}
Expand description
A helper trait for other threads to implement to be able to call methods on threads themselves.
use thread_priority::*;
assert!(std::thread::current().get_priority().is_ok());
let join_handle = std::thread::spawn(|| println!("Hello world!"));
assert!(join_handle.thread().get_priority().is_ok());
join_handle.join();
Required Methods§
Sourcefn get_native_id(&self) -> Result<ThreadId, Error>
fn get_native_id(&self) -> Result<ThreadId, Error>
Returns native unix thread id.
For more info read thread_native_id
.
use thread_priority::*;
assert!(std::thread::current().get_native_id().unwrap() > 0);
Provided Methods§
Sourcefn get_priority(&self) -> Result<ThreadPriority, Error>
fn get_priority(&self) -> Result<ThreadPriority, Error>
Gets the current thread’s priority.
For more info read get_current_thread_priority
.
use thread_priority::*;
assert!(std::thread::current().get_priority().is_ok());
Sourcefn set_priority(&self, priority: ThreadPriority) -> Result<(), Error>
fn set_priority(&self, priority: ThreadPriority) -> Result<(), Error>
Sets the current thread’s priority.
For more info see ThreadPriority::set_for_current
.
use thread_priority::*;
assert!(std::thread::current().set_priority(ThreadPriority::Min).is_ok());
Sourcefn get_schedule_policy(&self) -> Result<ThreadSchedulePolicy, Error>
fn get_schedule_policy(&self) -> Result<ThreadSchedulePolicy, Error>
Gets the current thread’s schedule policy.
For more info read thread_schedule_policy
.
Sourcefn get_schedule_policy_param(
&self,
) -> Result<(ThreadSchedulePolicy, ScheduleParams), Error>
fn get_schedule_policy_param( &self, ) -> Result<(ThreadSchedulePolicy, ScheduleParams), Error>
Returns current thread’s schedule policy and parameters.
For more info read thread_schedule_policy_param
.
Sourcefn set_priority_and_policy(
&self,
policy: ThreadSchedulePolicy,
priority: ThreadPriority,
) -> Result<(), Error>
fn set_priority_and_policy( &self, policy: ThreadSchedulePolicy, priority: ThreadPriority, ) -> Result<(), Error>
Sets current thread’s schedule policy.
For more info read set_thread_priority_and_policy
.
Implementations on Foreign Types§
Source§impl ThreadExt for Thread
impl ThreadExt for Thread
Auto-implementation of this trait for the std::thread::Thread
.