pub struct Thread { /* private fields */ }
Expand description
A handle to a running thread.
Implementations§
Source§impl Thread
impl Thread
pub fn handle(&self) -> &Handle
Sourcepub fn cycle_time(&self) -> WinResult<u64>
pub fn cycle_time(&self) -> WinResult<u64>
Returns the thread’s cycle time.
Sourcepub fn priority(&self) -> WinResult<PriorityLevel>
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.
Sourcepub fn set_priority(&mut self, priority: PriorityLevel) -> WinResult
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.
Sourcepub fn start_background_mode(&mut self) -> WinResult
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.
Sourcepub fn end_background_mode(&mut self) -> WinResult
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.
Sourcepub fn suspend(&mut self) -> WinResult<u32>
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.
Sourcepub fn resume(&mut self) -> WinResult<u32>
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.
Sourcepub fn terminate(&mut self, exit_code: u32) -> WinResult
pub fn terminate(&mut self, exit_code: u32) -> WinResult
Terminates the thread.
The handle must have the THREAD_TERMINATE
access right.
Sourcepub fn ideal_processor(&self) -> WinResult<u32>
pub fn ideal_processor(&self) -> WinResult<u32>
Returns the thread’s ideal processor.
Sourcepub fn set_ideal_processor(&mut self, processor: u32) -> WinResult<u32>
pub fn set_ideal_processor(&mut self, processor: u32) -> WinResult<u32>
Sets the thread’s ideal processor. On success, returns the previous ideal processor.
Sourcepub fn affinity_mask(&self) -> WinResult<usize>
pub fn affinity_mask(&self) -> WinResult<usize>
Returns the thread’s current affinity mask.
Sourcepub fn set_affinity_mask(&mut self, mask: usize) -> WinResult<usize>
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.
Sourcepub fn set_affinity(&mut self, processor: u8) -> WinResult<usize>
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.