Thread

Struct Thread 

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

Main thread handle with RAII resource management.

This represents a thread and automatically manages its resources through reference counting. When the last reference is dropped, the thread’s stack and other resources are automatically cleaned up.

Implementations§

Source§

impl Thread

Source

pub fn new( id: ThreadId, stack: Stack, entry_point: fn(), priority: u8, ) -> (Self, JoinHandle)

Create a new thread with the given parameters.

§Arguments
  • id - Unique identifier for this thread
  • stack - Stack allocated for this thread
  • entry_point - Function to execute in this thread
  • priority - Thread priority (0-255, higher = more important)
§Returns

A new Thread instance and corresponding JoinHandle.

Source

pub fn id(&self) -> ThreadId

Get the thread’s unique identifier.

Source

pub fn state(&self) -> ThreadState

Get the thread’s current state.

Source

pub fn set_state(&self, new_state: ThreadState)

Set the thread’s state.

§Arguments
  • new_state - The new state to set
Source

pub fn priority(&self) -> u8

Get the thread’s priority.

Source

pub fn set_priority(&self, new_priority: u8)

Set the thread’s priority.

§Arguments
  • new_priority - The new priority (0-255, higher = more important)
Source

pub fn is_runnable(&self) -> bool

Check if this thread is runnable (ready or running).

Source

pub fn context_ptr(&self) -> *mut <DefaultArch as Arch>::SavedContext

Get a pointer to the thread’s saved context.

§Returns

A pointer to the saved context, or null if not initialized.

Source

pub fn stack_bottom(&self) -> Option<*mut u8>

Get the thread’s stack bottom (initial stack pointer).

Source

pub fn check_stack_integrity(&self) -> bool

Check if the thread’s stack canary is intact (stack overflow detection).

Source

pub fn start_time_slice(&self)

Start a new time slice for this thread.

This should be called when the thread is scheduled to run.

Source

pub fn should_preempt(&self) -> bool

Update the thread’s virtual runtime and check if preemption is needed.

§Returns

true if the thread’s time slice has expired and it should be preempted.

Source

pub fn vruntime(&self) -> u64

Get the thread’s current virtual runtime.

This is used by the scheduler for fair scheduling decisions.

Source

pub fn set_name(&self, name: String)

Set the thread name for debugging purposes.

Source

pub fn name(&self) -> Option<String>

Get the thread name.

Source

pub fn set_cpu_affinity(&self, affinity: u64)

Set CPU affinity mask.

Source

pub fn cpu_affinity(&self) -> u64

Get CPU affinity mask.

Source

pub fn set_group_id(&self, group_id: u32)

Set thread group ID.

Source

pub fn group_id(&self) -> u32

Get thread group ID.

Source

pub fn set_time_slice(&self, duration: Duration)

Set custom time slice duration.

Source

pub fn set_critical(&self, critical: bool)

Set whether this thread is critical.

Source

pub fn is_critical(&self) -> bool

Check if this thread is critical.

Source

pub fn set_preemptible(&self, preemptible: bool)

Set whether this thread can be preempted.

Source

pub fn is_preemptible(&self) -> bool

Check if this thread can be preempted.

Source

pub fn reserve_tls(&self, size: usize)

Reserve thread-local storage space.

Source

pub fn tls_size(&self) -> usize

Get reserved TLS size.

Source

pub fn set_debug_info(&self, enabled: bool)

Enable or disable debug information.

Source

pub fn debug_info_enabled(&self) -> bool

Check if debug information is enabled.

Source

pub fn set_realtime_priority(&self, rt_priority: u8)

Set real-time priority.

Source

pub fn realtime_priority(&self) -> u8

Get real-time priority.

Source

pub fn set_nice_value(&self, nice: i8)

Set nice value for process priority.

Source

pub fn nice_value(&self) -> i8

Get nice value.

Source

pub fn set_inherit_signal_mask(&self, inherit: bool)

Set whether to inherit parent’s signal mask.

Source

pub fn inherits_signal_mask(&self) -> bool

Check if inheriting parent’s signal mask.

Source

pub fn set_environment(&self, env: BTreeMap<String, String>)

Set custom environment variables.

Source

pub fn environment(&self) -> Option<BTreeMap<String, String>>

Get environment variables.

Source

pub fn set_max_cpu_time(&self, max_time: u64)

Set maximum CPU time limit.

Source

pub fn max_cpu_time(&self) -> u64

Get maximum CPU time limit.

Source

pub fn set_max_memory(&self, max_memory: usize)

Set maximum memory usage limit.

Source

pub fn max_memory(&self) -> usize

Get maximum memory usage limit.

Source

pub fn set_max_files(&self, max_files: u32)

Set maximum file descriptors limit.

Source

pub fn max_files(&self) -> u32

Get maximum file descriptors limit.

Source

pub fn set_max_children(&self, max_children: u32)

Set maximum child threads limit.

Source

pub fn max_children(&self) -> u32

Get maximum child threads limit.

Source

pub fn record_memory_allocation(&self, size: u64)

Record memory allocation for this thread.

Source

pub fn record_memory_deallocation(&self, size: u64)

Record memory deallocation for this thread.

Source

pub fn record_cpu_time(&self, duration: Duration, user_mode: bool)

Record CPU time usage for this thread.

Source

pub fn update_stack_usage_metrics(&self, current_usage: usize)

Update stack usage for this thread.

Trait Implementations§

Source§

impl Clone for Thread

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Send for Thread

Source§

impl Sync for Thread

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.