Skip to main content

thread_attr

Attribute Macro thread_attr 

Source
#[thread_attr]
Expand description

#[ove::main] proc-macro: marks the application entry point. Expands into the extern "C" fn ove_main() trampoline. Attribute macro: declare a function as a thread entry-point with a statically-allocated stack. Calling the generated wrapper spawns the thread once; subsequent calls return Err(Error::Inval) (the underlying [ove::ThreadStorage] is single-use).

#[ove::thread(stack_size = 4096, name = "blinker")]
fn blink() {
    loop {
        ove::Thread::sleep_ms(500);
        ove::printk!("tick\n");
    }
}

fn ove_main() {
    blink().expect("spawn blinker");
    ove::run();
}

Generates:

  • A pub fn <name>() -> ove::Result<()> that, on first call, creates the thread with a static ThreadStorage<STACK_SIZE>.
  • The user’s original function body is moved into a hidden __ove_thread_<name>_body so the public <name> is the spawn helper.

Defaults: stack_size = 4096, name = "ove-thread" (override via the attribute args). The pool size is fixed at 1 — at most one live instance of the thread per program. Calling the spawn helper from inside the thread body itself is allowed but does nothing (returns Err); use [ove::Thread::builder] for dynamic spawns.

Works in both heap and zero-heap modes: the storage is static so no allocation happens at spawn time.