code wiki / (root) / nx_pool_ring_gate.nx

nx_pool_ring_gate.nx

buildroot/runtime/nx_pool_ring_gate.nx

3019 B90 linesdepth 7pulls 10 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_fmt.nx nx_pool_ring_gate.nx

imports: nx_thread_pool.nxnx_atom.nxnx_fmt.nx

imported by: nobody (leaf or entry point)

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

main 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 ↻ nx_pool_n_completed nx_atom_load_i64 nx_pool_submit nx_atom_faa_i64 nx_chan_send nx_chan_try_send _nx_chan_cell ↻ nx_thread_yield _pool_futex_wake_all sys_futex_wake nx_pool_wait nx_atom_load_i64 ↻ nx_thread_yield ↻ nx_atom_store_i64 _pool_futex_wait sys_futex_wait fmt_puts fmt_puts_fd sys_write rg_nl fmt_puts ↻ fmt_putn fmt_putn_fd sys_write ↻ nx_pool_shutdown

structs

none

consts

30const RG_N: i64 = 50000
31const RG_N2: i64 = 20000

functions

33func rg_task(ctx: i64) -> i64
calls 1: nx_atom_faa_i64
39func rg_nl() -> i64 { fmt_puts("\n" as *u8); return 0 }
called by 1: main calls 1: fmt_puts
41func main() -> i64