Struct zircon_object::task::SuspendToken[][src]

pub struct SuspendToken { /* fields omitted */ }

Suspend the given task.

Currently only thread or process handles may be suspended.

Example

let job = Job::root();
let proc = Process::create(&job, "proc").unwrap();
let thread = Thread::create(&proc, "thread").unwrap();

// start the thread and never terminate
thread.start(0, 0, 0, 0, |thread| Box::pin(async move {
    loop { async_std::task::yield_now().await }
    let _ = thread;
})).unwrap();

// wait for the thread running
let object: Arc<dyn KernelObject> = thread.clone();
async_std::task::block_on(object.wait_signal(Signal::THREAD_RUNNING));
assert_eq!(thread.state(), ThreadState::Running);

// suspend the thread
{
    let task: Arc<dyn Task> = thread.clone();
    let suspend_token = SuspendToken::create(&task);
    assert_eq!(thread.state(), ThreadState::Suspended);
}
// suspend token dropped, resume the thread
assert_eq!(thread.state(), ThreadState::Running);

Implementations

impl SuspendToken[src]

pub fn create(task: &Arc<dyn Task>) -> Arc<Self>[src]

Create a SuspendToken which can suspend the given task.

Trait Implementations

impl Debug for SuspendToken[src]

impl Drop for SuspendToken[src]

impl KernelObject for SuspendToken[src]

Auto Trait Implementations

impl !RefUnwindSafe for SuspendToken

impl Send for SuspendToken

impl Sync for SuspendToken

impl Unpin for SuspendToken

impl !UnwindSafe for SuspendToken

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.