Struct zircon_object::task::Thread [−][src]
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
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]
proc: &Arc<Process>,
name: &str,
ext: impl Any + Send + Sync
) -> ZxResult<Arc<Self>>
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]
self: &Arc<Self>,
entry: usize,
stack: usize,
arg1: usize,
arg2: usize,
thread_fn: ThreadFn
) -> ZxResult
Start execution on the thread.
pub fn start_with_regs(
self: &Arc<Self>,
regs: GeneralRegs,
thread_fn: ThreadFn
) -> ZxResult
[src]
self: &Arc<Self>,
regs: GeneralRegs,
thread_fn: ThreadFn
) -> ZxResult
Start execution with given registers.
pub fn read_state(
&self,
kind: ThreadStateKind,
buf: &mut [u8]
) -> ZxResult<usize>
[src]
&self,
kind: ThreadStateKind,
buf: &mut [u8]
) -> ZxResult<usize>
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]
fn id(&self) -> KoID
[src]
fn type_name(&self) -> &str
[src]
fn name(&self) -> String
[src]
fn set_name(&self, name: &str)
[src]
fn signal(&self) -> Signal
[src]
fn signal_set(&self, signal: Signal)
[src]
fn signal_clear(&self, signal: Signal)
[src]
fn signal_change(&self, clear: Signal, set: Signal)
[src]
fn add_signal_callback(&self, callback: SignalHandler)
[src]
fn related_koid(&self) -> KoID
[src]
fn get_child(&self, _id: KoID) -> ZxResult<Arc<dyn KernelObject>>
[src]
fn peer(&self) -> ZxResult<Arc<dyn KernelObject>>
[src]
fn allowed_signals(&self) -> Signal
[src]
impl Task for Thread
[src]
fn kill(&self)
[src]
fn suspend(&self)
[src]
fn resume(&self)
[src]
fn exceptionate(&self) -> Arc<Exceptionate>
[src]
fn debug_exceptionate(&self) -> Arc<Exceptionate>
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
[src]
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any,
[src]
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,