Struct Thread

Source
pub struct Thread { /* private fields */ }
Expand description

A handle to a running thread.

Implementations§

Source§

impl Thread

Source

pub fn from_id(id: u32) -> WinResult<Thread>

Creates a thread handle from a thread ID.

Source

pub fn current() -> Thread

Returns a handle to the current thread.

Source

pub fn handle(&self) -> &Handle

Source

pub fn id(&self) -> u32

Return’s the thread’s ID.

Source

pub fn cycle_time(&self) -> WinResult<u64>

Returns the thread’s cycle time.

Source

pub fn priority(&self) -> WinResult<PriorityLevel>

Returns the priority level of the thread.

The handle must have the THREAD_QUERY_INFORMATION or THREAD_QUERY_LIMITED_INFORMATION access right.

Source

pub fn set_priority(&mut self, priority: PriorityLevel) -> WinResult

Sets the priority level of the thread.

The handle must have the THREAD_SET_INFORMATION or THREAD_SET_LIMITED_INFORMATION access right.

Source

pub fn start_background_mode(&mut self) -> WinResult

Begins background processing mode.

This can be initiated only if the handle refers to the current thread.

The system lowers the resource scheduling priorities of the thread so that it can perform background work without significantly affecting activity in the foreground.

The function fails if the thread is already in background processing mode.

The handle must have the THREAD_SET_INFORMATION or THREAD_SET_LIMITED_INFORMATION access right.

Source

pub fn end_background_mode(&mut self) -> WinResult

Ends background processing mode.

This can be initiated only if the handle refers to the current thread.

The system restores the resource scheduling priorities of the thread as they were before the thread entered background processing mode.

The function fails if the thread is not in background processing mode.

The handle must have the THREAD_SET_INFORMATION or THREAD_SET_LIMITED_INFORMATION access right.

Source

pub fn suspend(&mut self) -> WinResult<u32>

Suspends the thread.

If the function succeeds, the return value is the thread’s previous suspend count.

The handle must have the THREAD_SUSPEND_RESUME access right.

Source

pub fn resume(&mut self) -> WinResult<u32>

Resumes the thread.

If the function succeeds, the return value is the thread’s previous suspend count.

The handle must have the THREAD_SUSPEND_RESUME access right.

Source

pub fn terminate(&mut self, exit_code: u32) -> WinResult

Terminates the thread.

The handle must have the THREAD_TERMINATE access right.

Source

pub fn ideal_processor(&self) -> WinResult<u32>

Returns the thread’s ideal processor.

Source

pub fn set_ideal_processor(&mut self, processor: u32) -> WinResult<u32>

Sets the thread’s ideal processor. On success, returns the previous ideal processor.

Source

pub fn affinity_mask(&self) -> WinResult<usize>

Returns the thread’s current affinity mask.

Source

pub fn set_affinity_mask(&mut self, mask: usize) -> WinResult<usize>

Sets the affinity mask of the thread. On success, returns the previous affinity mask.

A thread affinity mask is a bit vector in which each bit represents a logical processor that a thread is allowed to run on. A thread affinity mask must be a subset of the process affinity mask for the containing process of a thread. A thread can only run on the processors its process can run on. Therefore, the thread affinity mask cannot specify a 1 bit for a processor when the process affinity mask specifies a 0 bit for that processor.

Setting an affinity mask for a process or thread can result in threads receiving less processor time, as the system is restricted from running the threads on certain processors. In most cases, it is better to let the system select an available processor.

If the new thread affinity mask does not specify the processor that is currently running the thread, the thread is rescheduled on one of the allowable processors.

Source

pub fn set_affinity(&mut self, processor: u8) -> WinResult<usize>

Sets the affinity of the thread to the single specified processor.

If the processor index equals or exceeds the width of usize, the mask is not changed. On success, or if unchanged, returns the previous affinity mask.

Trait Implementations§

Source§

impl AsRawHandle for Thread

Source§

fn as_raw_handle(&self) -> RawHandle

Extracts the raw handle. Read more
Source§

impl Debug for Thread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Thread

Source§

type Target = *mut c_void

The resulting type after dereferencing.
Source§

fn deref(&self) -> &HANDLE

Dereferences the value.
Source§

impl FromRawHandle for Thread

Source§

unsafe fn from_raw_handle(handle: RawHandle) -> Thread

Constructs a new I/O object from the specified raw handle. Read more
Source§

impl IntoRawHandle for Thread

Source§

fn into_raw_handle(self) -> RawHandle

Consumes this object, returning the raw underlying handle. Read more

Auto Trait Implementations§

§

impl Freeze for Thread

§

impl RefUnwindSafe for Thread

§

impl !Send for Thread

§

impl !Sync for Thread

§

impl Unpin for Thread

§

impl UnwindSafe for Thread

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.