ThreadBuilder

Struct ThreadBuilder 

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

Builder for configuring and creating new threads.

This provides a comprehensive interface for setting thread parameters before spawning, with advanced options for scheduling, debugging, and resource management.

Implementations§

Source§

impl ThreadBuilder

Source

pub fn new() -> Self

Create a new thread builder with default settings.

Source

pub fn stack_size_class(self, size_class: StackSizeClass) -> Self

Set the stack size class for the thread.

Source

pub fn stack_size(self, size: usize) -> Self

Set the stack size in bytes.

Source

pub fn priority(self, priority: u8) -> Self

Set the thread priority.

Source

pub fn name<T: Into<String>>(self, name: T) -> Self

Set the thread name for debugging purposes.

Source

pub fn cpu_affinity(self, mask: u64) -> Self

Set CPU affinity mask (which CPUs this thread can run on).

Source

pub fn group_id(self, group: u32) -> Self

Set thread group ID for resource accounting.

Source

pub fn stack_guard_pages(self, enabled: bool) -> Self

Enable or disable stack guard pages (requires MMU feature).

Source

pub fn stack_canary(self, enabled: bool) -> Self

Enable or disable stack canary protection.

Source

pub fn custom_canary(self, canary: u64) -> Self

Set custom stack canary value.

Source

pub fn time_slice(self, duration: Duration) -> Self

Set custom time slice duration.

Source

pub fn critical(self, critical: bool) -> Self

Mark this thread as critical (affects scheduling priority).

Source

pub fn preemptible(self, preemptible: bool) -> Self

Set whether this thread can be preempted.

Source

pub fn tls_size(self, size: usize) -> Self

Reserve space for thread-local storage.

Source

pub fn debug_info(self, enabled: bool) -> Self

Enable or disable detailed debugging information.

Source

pub fn attributes(self, attributes: ThreadAttributes) -> Self

Set custom thread attributes.

Source

pub fn spawn( self, thread_id: ThreadId, stack_pool: &StackPool, entry_point: fn(), ) -> Result<(Thread, JoinHandle), SpawnError>

Spawn a new thread with the configured parameters.

§Arguments
  • thread_id - Unique identifier for the new thread
  • stack_pool - Stack pool to allocate from
  • entry_point - Function to run in the new thread
§Returns

A tuple of (Thread, JoinHandle) if successful, or an error if thread creation fails.

Trait Implementations§

Source§

impl Default for ThreadBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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.