CPU-bound tasks
A long C loop can delay cancellation, watchdog progress, and other tasks. Use managed C, or add safepoints to compatibility tasks.
On this page
Use managed C
Compiler-qualified tasks use native asynchronous preemption by default through
llam_runtime_create() or llam_runtime_init(), after image admission and
native-thread probes. llam_runtime_create_managed() exposes advanced policy
and budget settings. Select the requested managed policy through llam_preempt_opts_t and
query the effective policy with llam_runtime_preempt_info_ex(); see the
managed C guide and its native profile limits.
Add safepoints to compatibility tasks
Explicit *_compat constructors retain boundary/safepoint preemption. Their
watchdog/runtime policy requests a switch, but the task must still hit a
boundary such as llam_task_safepoint(), LLAM_PREEMPT_POLL,
LLAM_PREEMPT_POLL_EVERY, llam_yield(), a wait, or an I/O call. Long C loops
that never reach one of those boundaries can delay cancellation, watchdog
progress, allocator quiescence, and runnable task handoff.
Use LLAM_PREEMPT_POLL_EVERY inside CPU-heavy loops when an immediate yield
would be too expensive, and use llam_yield() when fairness matters more than
raw loop throughput.
size_t poll_counter = 0;
for (uint64_t i = 0; i < work_items; ++i) {
process_item(i);
LLAM_PREEMPT_POLL_EVERY(poll_counter++, 1024U);
}
Tune safepoints
Compatibility/safepoint tuning knobs:
LLAM_PREEMPT_MODE=off|cooperative|auto|strictselects the preemption policy.autois the normal diagnostic-safe mode;strictis for finding loops that do not poll often enough.offandcooperativeapply only to compatibility runtimes; the ordinary constructors reject them withEINVAL.LLAM_PREEMPT_POLL_PERIODoverrides the task-local safepoint flag-poll period. Use this only when measuring CPU-loop latency vs overhead.LLAM_PREEMPT_QUANTUM_NSoverrides the runtime slice budget. Keep it at0unless a benchmark or incident investigation needs a fixed quantum.LLAM_SAFEPOINT_CLOCK_PERIODcontrols cheap-safepoint clock sampling and can reduce timestamp overhead in very hot loops.