pub fn start(
        &self,
        thread: &Arc<Thread>,
        entry: usize,
        stack: usize,
        arg1: Option<Handle>,
        arg2: usize,
        thread_fn: ThreadFn,
    ) -> ZxResult {
        let handle_value;
        {
            let mut inner = self.inner.lock();
            if !inner.contains_thread(thread) {
                return Err(ZxError::ACCESS_DENIED);
            }
            if inner.status != Status::Init {
                return Err(ZxError::BAD_STATE);
            }
            inner.status = Status::Running;
            handle_value = arg1.map_or(INVALID_HANDLE, |handle| inner.add_handle(handle));
        }
        thread.set_first_thread();
        match thread.start(entry, stack, handle_value as usize, arg2, thread_fn) {
            Ok(_) => Ok(()),
            Err(err) => {
                let mut inner = self.inner.lock();
                if handle_value != INVALID_HANDLE {
                    inner.remove_handle(handle_value).ok();
                }
                Err(err)
            }
        }
    }
/// Start the first thread in the process.
///
/// This causes a thread to begin execution at the program
/// counter specified by `entry` and with the stack pointer set to `stack`.
/// The arguments `arg1` and `arg2` are arranged to be in the architecture
/// specific registers used for the first two arguments of a function call
/// before the thread is started. All other registers are zero upon start.
///
/// # Example
/// ```
/// # use std::sync::Arc;
/// # use zircon_object::task::*;
/// # use zircon_object::object::*;
/// # kernel_hal::init();
/// # async_std::task::block_on(async {
/// let job = Job::root();
/// let proc = Process::create(&job, "proc").unwrap();
/// let thread = Thread::create(&proc, "thread").unwrap();
/// let handle = Handle::new(proc.clone(), Rights::DEFAULT_PROCESS);
///
/// // start the new thread
/// proc.start(&thread, 1, 4, Some(handle), 2, |thread| Box::pin(async move {
///     let cx = thread.wait_for_run().await;
///     assert_eq!(cx.general.rip, 1);  // entry
///     assert_eq!(cx.general.rsp, 4);  // stack_top
///     assert_eq!(cx.general.rdi, 3);  // arg0 (handle)
///     assert_eq!(cx.general.rsi, 2);  // arg1
///     thread.end_running(cx);
/// })).unwrap();
///
/// # let object: Arc<dyn KernelObject> = thread.clone();
/// # object.wait_signal(Signal::THREAD_TERMINATED).await;
/// # });
/// ```
Start the first thread in the process.
This causes a thread to begin execution at the program
counter specified by `entry` and with the stack pointer set to `stack`.
The arguments `arg1` and `arg2` are arranged to be in the architecture
specific registers used for the first two arguments of a function call
before the thread is started. All other registers are zero upon start.
Start the first thread in the process . This causes a thread to begin execution at the program counter specified by ` entry ` and with the stack pointer set to ` stack ` . The arguments ` arg1 ` and ` arg2 ` are arranged to be in the architecture specific registers used for the first two arguments of a function call before the thread is started . All other registers are zero upon start .
pub fn start(
        &self,
        thread: &Arc<Thread>,
        entry: usize,
        stack: usize,
        arg1: Option<Handle>,
        arg2: usize,
        thread_fn: ThreadFn,
    ) -> ZxResult {
        let handle_value;
        {
            let mut inner = self.inner.lock();
            if !inner.contains_thread(thread) {
                return Err(ZxError::ACCESS_DENIED);
            }
            if inner.status != Status::Init {
                return Err(ZxError::BAD_STATE);
            }
            inner.status = Status::Running;
            handle_value = arg1.map_or(INVALID_HANDLE, |handle| inner.add_handle(handle));
        }
        thread.set_first_thread();
        match thread.start(entry, stack, handle_value as usize, arg2, thread_fn) {
            Ok(_) => Ok(()),
            Err(err) => {
                let mut inner = self.inner.lock();
                if handle_value != INVALID_HANDLE {
                    inner.remove_handle(handle_value).ok();
                }
                Err(err)
            }
        }
    }
pub fn start ( & self , thread : & Arc < Thread > , entry : usize , stack : usize , arg1 : Option < Handle > , arg2 : usize , thread_fn : ThreadFn , ) -> ZxResult { let handle_value ; { let mut inner = self . inner . lock ( ) ; if ! inner . contains_thread ( thread ) { return Err ( ZxError :: ACCESS_DENIED ) ; } if inner . status != Status :: Init { return Err ( ZxError :: BAD_STATE ) ; } inner . status = Status :: Running ; handle_value = arg1 . map_or ( INVALID_HANDLE , | handle | inner . add_handle ( handle ) ) ; } thread . set_first_thread ( ) ; match thread . start ( entry , stack , handle_value as usize , arg2 , thread_fn ) { Ok ( _ ) => Ok ( ( ) ) , Err ( err ) => { let mut inner = self . inner . lock ( ) ; if handle_value != INVALID_HANDLE { inner . remove_handle ( handle_value ) . ok ( ) ; } Err ( err ) } } }
Start the first thread in the process.
Start the first thread in the process .
&self
thread
&Arc<Thread>
entry
usize
stack
usize
arg1
Option<Handle>
arg2
usize
thread_fn
ThreadFn
&self
thread
&Arc<Thread>
entry
usize
stack
usize
arg1
Option<Handle>
arg2
usize
thread_fn
ThreadFn
example
None
use std::sync::arc;
None
use zircon_object::task::*;
None
use zircon_object::object::*;
None
kernel_hal::init();
None
async_std::task::block_on(async {
let job = Job::root();
let proc = Process::create(&job, "proc").unwrap();
let thread = Thread::create(&proc, "thread").unwrap();
let handle = Handle::new(proc.clone(), Rights::DEFAULT_PROCESS).

start the new thread
proc.start(&thread, 1, 4, Some(handle), 2, |thread| Box::pin(async move {
let cx = thread.wait_for_run().await;
assert_eq!(cx.general.rip, 1);  // entry
assert_eq!(cx.general.rsp, 4);  // stack_top
assert_eq!(cx.general.rdi, 3);  // arg0 (handle)
assert_eq!(cx.general.rsi, 2);  // arg1
thread.end_running(cx);
})).unwrap().
let job = Job :: root () ; let proc = Process :: create ( &job " proc " ) . unwrap () ; let thread = Thread :: create ( &proc " thread " ) . unwrap () ; let handle = Handle :: new ( proc . clone () Rights :: DEFAULT_PROCESS ) . start the new thread proc . start ( &thread 1 4 Some ( handle ) 2 |thread| Box :: pin ( async move { let cx = thread . wait_for_run () . await ; assert_eq! ( cx . general . rip 1 ) ; // entry assert_eq! ( cx . general . rsp 4 ) ; // stack_top assert_eq! ( cx . general . rdi 3 ) ; // arg0 ( handle ) assert_eq! ( cx . general . rsi 2 ) ; // arg1 thread . end_running ( cx ) ; } )) . unwrap () .
let object: arc<dyn kernelobject> = thread.clone();
None
object.wait_signal(signal::thread_terminated).await;
None
});
None