async fn new_thread(thread: CurrentThread) {
    loop {
        // wait
        let mut cx = thread.wait_for_run().await;
        if thread.state() == ThreadState::Dying {
            break;
        }

        // run
        trace!("go to user: {:#x?}", cx);
        kernel_hal::context::context_run(&mut cx);
        trace!("back from user: {:#x?}", cx);
        // handle trap/interrupt/syscall

        if let Err(err) = handler_user_trap(&thread, &mut cx).await {
            thread.exit_linux(err as i32);
        }

        thread.end_running(cx);
    }
}
/// The function of a new thread.
///
/// loop:
/// - wait for the thread to be ready
/// - get user thread context
/// - enter user mode
/// - handle trap/interrupt/syscall according to the return value
/// - return the context to the user thread
The function of a new thread.
loop:
wait for the thread to be ready
get user thread context
enter user mode
handle trap/interrupt/syscall according to the return value
return the context to the user thread
The function of a new thread . loop : wait for the thread to be ready get user thread context enter user mode handle trap / interrupt / syscall according to the return value return the context to the user thread
async fn new_thread(thread: CurrentThread) {
    loop {
        // wait
        let mut cx = thread.wait_for_run().await;
        if thread.state() == ThreadState::Dying {
            break;
        }
        // run
        trace!("go to user: {:#x?}", cx);
        kernel_hal::context::context_run(&mut cx);
        trace!("back from user: {:#x?}", cx);
        // handle trap/interrupt/syscall
        if let Err(err) = handler_user_trap(&thread, &mut cx).await {
            thread.exit_linux(err as i32);
        }
        thread.end_running(cx);
    }
}
async fn new_thread ( thread : CurrentThread ) { loop { // wait let mut cx = thread . wait_for_run ( ) . await ; if thread . state ( ) == ThreadState :: Dying { break ; } // run trace ! ( " " cx ) ; kernel_hal :: context :: context_run ( & mut cx ) ; trace ! ( " " cx ) ; // handle trap/interrupt/syscall if let Err ( err ) = handler_user_trap ( & thread , & mut cx ) . await { thread . exit_linux ( err as i32 ) ; } thread . end_running ( cx ) ; } }
The function of a new thread.
The function of a new thread .
thread
CurrentThread
thread
CurrentThread