Skip to main content

Module thread

Module thread 

Source
Expand description

RTOS thread management.

The API splits the thread surface into three types so ownership, observation, and configuration each have a clear home:

  • Thread is a non-owning handle. Returned by Thread::current and by JoinHandle::thread. Carries the read-only and signal operations (get_state, get_stack_usage, set_priority, suspend/resume, request_stop, …). Dropping a Thread value does nothing.
  • JoinHandle is the owning type returned by Builder::spawn (and its spawn_cooperative/spawn_simple/ spawn_static siblings). On drop it calls JoinHandle::request_stop and waits for the worker to finish. Use JoinHandle::detach to opt out of the join-on-drop.
  • Builder is the only way to spawn a new thread. Cooperative cancellation is opt-in via the closure signature (FnOnce(StopToken) vs fn()).

Spawning a cooperative worker:

let h = Thread::builder()
    .name(c"worker")
    .priority(Priority::Normal)
    .stack_size(4096)
    .spawn(|tok: StopToken| {
        while !tok.is_stopped() { /* work */ }
    })?;
// h goes out of scope -> request_stop + join, no deadlock.

Spawning a self-terminating one-shot (no token):

fn entry() { /* one-shot work */ }
let _h = Thread::builder()
    .name(c"oneshot")
    .priority(Priority::Normal)
    .stack_size(4096)
    .spawn_simple(entry)?;

Structs§

Builder
Fluent thread-spawn configuration. Construct via Thread::builder.
JoinHandleBorrowed
Owning handle to a spawned RTOS thread.
MemStats
System heap statistics.
StopToken
Read-only handle to a thread’s cooperative-cancellation flag.
Thread
Non-owning handle to an RTOS thread.
ThreadInfo
Snapshot of a single thread’s info.
ThreadStats
Runtime statistics for a thread.

Enums§

Priority
Thread priority levels, matching ove_prio_t.
ThreadState
Thread state, matching ove_thread_state_t.

Functions§

get_mem_stats
Query system heap statistics.
thread_list
List all threads in the system.

Type Aliases§

JoinHandle
Heap-mode JoinHandle. Alias of JoinHandleBorrowed with 'storage = 'static (kernel owns the storage, no caller borrow). Matches the shape of std::thread::JoinHandle for source-level compatibility with std-style code.