Struct zircon_object::task::Thread[][src]

pub struct Thread { /* fields omitted */ }

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:

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

impl Thread[src]

pub fn create(proc: &Arc<Process>, name: &str) -> ZxResult<Arc<Self>>[src]

Create a new thread.

pub fn create_with_ext(
    proc: &Arc<Process>,
    name: &str,
    ext: impl Any + Send + Sync
) -> ZxResult<Arc<Self>>
[src]

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));

pub fn proc(&self) -> &Arc<Process>[src]

Get the process.

pub fn ext(&self) -> &Box<dyn Any + Send + Sync>[src]

Get the extension info.

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

Start execution on the thread.

pub fn start_with_regs(
    self: &Arc<Self>,
    regs: GeneralRegs,
    thread_fn: ThreadFn
) -> ZxResult
[src]

Start execution with given registers.

pub fn read_state(
    &self,
    kind: ThreadStateKind,
    buf: &mut [u8]
) -> ZxResult<usize>
[src]

Read one aspect of thread state.

pub fn write_state(&self, kind: ThreadStateKind, buf: &[u8]) -> ZxResult[src]

Write one aspect of thread state.

pub fn get_thread_info(&self) -> ThreadInfo[src]

Get the thread’s information.

pub fn get_thread_exception_info(&self) -> ZxResult<ExceptionReport>[src]

Get the thread’s exception report.

pub fn state(&self) -> ThreadState[src]

Get the thread state.

pub fn time_add(&self, time: u128)[src]

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

pub fn get_time(&self) -> u64[src]

Get the time this thread has run on cpu.

pub fn is_first_thread(&self) -> bool[src]

Whether this thread is the first thread of a process.

pub fn flags(&self) -> ThreadFlag[src]

Get the thread’s flags.

pub fn update_flags(&self, f: impl FnOnce(&mut ThreadFlag))[src]

Apply f to the thread’s flags.

pub fn set_fsbase(&self, fsbase: usize) -> ZxResult[src]

Set the thread local fsbase register on x86_64.

pub fn set_gsbase(&self, gsbase: usize) -> ZxResult[src]

Set the thread local gsbase register on x86_64.

Trait Implementations

impl Debug for Thread[src]

impl KernelObject for Thread[src]

impl Task for Thread[src]

Auto Trait Implementations

impl !RefUnwindSafe for Thread

impl Send for Thread

impl Sync for Thread

impl Unpin for Thread

impl !UnwindSafe for Thread

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.