code wiki / (root) / nx_thread_spawn_test.nx

nx_thread_spawn_test.nx

buildroot/runtime/nx_thread_spawn_test.nx

4208 B116 linesdepth 6pulls 12 transitivereach 0 importersview sourcekind gate/prooftopic thread
docsdependenciesstructsconstsfunctions

about

nx_thread_spawn_test.nx -- end-to-end test for __thread_clone: real OS thread spawn + atomic counter bumping + spin-join. Strategy: parent allocates a shared counter (mmap'd page so child sees the same memory), spawns a worker thread that bumps the counter N times via atomic FAA, then spin-waits until the counter hits N. No futex/condvar needed for this smoke -- just proves the child trampoline works and that atomics propagate cross-thread. Per cardinal end-to-end-or-dont-ship: this test EXERCISES the trampoline rather than just compiling it. Runs under qemu-riscv64-static which emulates clone() correctly.

dependencies 5 imports · 0 importers

nx_kernel_v2.nx nx_log.nx nx_atom.nx nx_thread.nx nx_hw.nx nx_thread_spawn_test.nx

imports: nx_kernel_v2.nxnx_log.nxnx_atom.nxnx_thread.nxnx_hw.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_thread_spawn_fn sys_mmap nx_atom_load_i64 nx_hw_worker_count nx_hw_cpu_count sys_mmap ↻ sys_munmap

structs

none

consts

20const ITERATIONS_PER_THREAD: i64 = 10000
27const STRESS_FACTOR: i64 = 4

functions

32func worker_bump(arg: *u8) -> i64
calls 1: nx_atom_faa_i64
42func main() -> nx_exit