code wiki / (root) / nx_pool_ring_gate.nx

nx_pool_ring_gate.nx

buildroot/runtime/nx_pool_ring_gate.nx

4314 B92 linesdepth 7pulls 11 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_pool_ring_gate.nx -- regression witness for the RING ARENA fix in nx_thread_pool (2026-07-08). The task arena was a bump allocator (16384 slots); past that, nx_pool_submit returned -1 without queuing, and a caller that then delta-waited spun to the 2-billion timeout. A long-lived shared pool (the LLM forward submits thousands of tasks per token) hit this and wedged 428s/token. Fix: slot index wraps modulo arena_cap; SAFE because channel depth << arena_cap so a slot is consumed long before the ring wraps back to it. This gate submits N >> arena_cap tasks to ONE pool (forcing several full ring wraps), each atomically incrementing a shared counter, and verifies EVERY task ran exactly once -- the exact scenario that silently dropped tasks before. Checks: 1 shared counter == N (no task lost to a dropped submit) 2 pool completed-counter == N (delta-wait saw them all) 3 a SECOND batch on the same pool also completes (reuse across the wrap boundary) lineage_id: pool_ring_gate_v1

dependencies 3 imports · 0 importers

nx_thread_pool.nx nx_atom.nx nx_gate_verdict.nx nx_pool_ring_gate.nx

imports: nx_thread_pool.nxnx_atom.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

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

main gv_ctr sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ gv_head gv_puts sys_write ↻ nx_pool_new nx_hw_worker_count nx_hw_cpu_count sys_mmap ↻ sys_munmap sys_mmap ↻ nx_chan_new sys_mmap ↻ _nx_chan_cell sys_thread_create nx_thread_spawn sys_mmap ↻ nx_thread_spawn_fn sys_mmap ↻ rg_kv gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap ↻

structs

none

consts

38const RG_N: i64 = 50000
39const RG_N2: i64 = 20000

functions

41func rg_task(ctx: i64) -> i64
calls 1: nx_atom_faa_i64
47func rg_kv(k: *u8, v: i64) -> i64 { gv_puts(k); gv_num(v); gv_puts("\n" as *u8); return 0 }
called by 1: main calls 2: gv_putsgv_num
49func main() -> i64