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

Runnable / computation entity

SYNOPSIS

TODO

DESCRIPTION

The thread object is the construct that represents a time-shared CPU execution context. Thread objects live associated to a particular Process Object which provides the memory and the handles to other objects necessary for I/O and computation.

Lifetime

Threads are created by calling Thread::create(), but only start executing when either Thread::start() or Process::start() are called. Both syscalls take as an argument the entrypoint of the initial routine to execute.

The thread passed to Process::start() should be the first thread to start execution on a process.

A thread terminates execution:

  • by calling CurrentThread::exit()
  • when the parent process terminates
  • by calling Task::kill()
  • after generating an exception for which there is no handler or the handler decides to terminate the thread.

Returning from the entrypoint routine does not terminate execution. The last action of the entrypoint should be to call CurrentThread::exit().

Closing the last handle to a thread does not terminate execution. In order to forcefully kill a thread for which there is no available handle, use KernelObject::get_child() to obtain a handle to the thread. This method is strongly discouraged. Killing a thread that is executing might leave the process in a corrupt state.

Fuchsia native threads are always detached. That is, there is no join() operation needed to do a clean termination. However, some runtimes above the kernel, such as C11 or POSIX might require threads to be joined.

Signals

Threads provide the following signals:

When a thread is started THREAD_RUNNING is asserted. When it is suspended THREAD_RUNNING is deasserted, and THREAD_SUSPENDED is asserted. When the thread is resumed THREAD_SUSPENDED is deasserted and THREAD_RUNNING is asserted. When a thread terminates both THREAD_RUNNING and THREAD_SUSPENDED are deasserted and THREAD_TERMINATED is asserted.

Note that signals are OR’d into the state maintained by the KernelObject::wait_signal() family of functions thus you may see any combination of requested signals when they return.

Implementations

Create a new thread.

Create a new thread with extension info.

Example
let job = Job::root();
let proc = Process::create(&job, "proc").unwrap();
// create a thread with extension info
let thread = Thread::create_with_ext(&proc, "thread", job.clone()).unwrap();
// get the extension info
let ext = thread.ext().downcast_ref::<Arc<Job>>().unwrap();
assert!(Arc::ptr_eq(ext, &job));

Get the process.

Get the extension info.

Returns a copy of saved context of current thread, or Err(ZxError::BAD_STATE) if the thread is running.

Access saved context of current thread, or Err(ZxError::BAD_STATE) if the thread is running.

Backup current user context before calling signal handler

Fetch the context backup

Start execution on the thread.

source

pub fn start_with_entry(
    self: &Arc<Self>,
    entry: usize,
    stack: usize,
    arg1: usize,
    arg2: usize,
    thread_fn: ThreadFn
) -> ZxResult

Setup the instruction and stack pointer, then tart execution on the thread

Read one aspect of thread state.

Write one aspect of thread state.

Get the thread’s information.

Get the thread’s exception report.

Get the thread state.

Add the parameter to the time this thread has run on cpu.

Get the time this thread has run on cpu.

Whether this thread is the first thread of a process.

Get the thread’s flags.

Apply f to the thread’s flags.

Trait Implementations

Formats the value using the given formatter. Read more

Get object’s KoID.

Get the name of the type of the kernel object.

Get object’s name.

Set object’s name.

Get the signal status.

Assert signal.

Deassert signal.

Change signal status: first clear then set indicated bits. Read more

Add callback for signal status changes. Read more

If the object is related to another (such as the other end of a channel, or the parent of a job), returns the KoID of that object, otherwise returns zero. Read more

Attempt to find a child of the object with given KoID. Read more

Attempt to get the object’s peer. Read more

Get object’s allowed signals.

Kill the task. The task do not terminate immediately when killed. It will terminate after all its children are terminated or some cleanups are finished. Read more

Suspend the task. Currently only thread or process handles may be suspended.

Resume the task

Get the exceptionate.

Get the debug exceptionate.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Casts the value.

Casts the value.

Casts the value.

Casts the value.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.

Casts the value.

Casts the value.