Skip to main content

nova_rt_task_spawn

Function nova_rt_task_spawn 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C-unwind" fn nova_rt_task_spawn( future: *mut u8, ) -> i64
Expand description

Queue a { poll_code, state } future as a new task and return its id.

"C-unwind": see PollFn’s doc comment for why every entry point in this module shares that ABI rather than plain "C".

§Safety

future must point to a live FUTURE_SIZE-byte { poll_code, state } block, and:

  • poll_code (FUTURE_SLOT_POLL) must be a non-null PollFn address (see [read_future] for why null is undefined behaviour here, not a later fault);
  • state (FUTURE_SLOT_STATE) must point to a live, writable block of at least (STATE_SLOT_TEMPS + n_temps) * 8 bytes, and never fewer than STATE_MIN_SIZE. STATE_SLOT_OUTPUT is read unconditionally on completion – including for a future whose async fn returns unit and has no temps, where nothing in the poll function itself ever touches that slot. A tag-only 8-byte state object satisfies neither this contract nor the executor’s read, and would be read 8 bytes past its allocation;
  • state must be allocated scanned (gc::alloc(.., true), which is what nova_rt_alloc does): a heap-valued output written to STATE_SLOT_OUTPUT is kept alive by tracing through the state object, so an unscanned state object would let it be collected (see [poll_one]).