code wiki / _hdl_build / nx_arbiter_race_gate.nx

nx_arbiter_race_gate.nx

buildroot/runtime/_hdl_build/nx_arbiter_race_gate.nx

5197 B104 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic arbiter
docsdependenciesstructsconstsfunctions

about

nx_arbiter_race_gate.nx -- MEASURED before/after proof that nx_arbiter turns F-class coordination into S-class on a REAL shared-sink race. RG_N child PROCESSES (sys_fork -- our own kernel clone, no shell) each do RG_K iterations of: read counter file -> increment -> write back. That read-modify-write is EXACTLY the pattern that clobbered MEMORY.md + genesis_lineage.tsv mid-write today. A 0.5ms window between read and write forces the scheduler to interleave the children. UNLOCKED : writers race -> updates are lost -> final count << RG_N*RG_K. ARBITRATED: fl_acquire serializes the critical section -> final count == RG_N*RG_K, exactly, every run. Self-contained + sovereign: our fork/wait4 + our flock-based arbiter + our counter file. No 3rd party, no shell-driven race. GREEN iff (a) the unlocked race PROVABLY loses updates AND (b) the arbiter eliminates every one of them. This is the honest measured exceed -- a number, not a claim. license_tier: ORIGINAL

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_arbiter.nx nx_runpath.nx nx_arbiter_race_gate.nx

imports: nx_syscalls.nxnx_arbiter.nxnx_runpath.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap g_w sys_write rp_wsid sys_openat_rd sys_mmap ↻ sys_read sys_close rp_match rp_ensure sys_mmap ↻ rp_path rg_phase rg_write sys_openat_wr sys_mmap ↻ sys_write ↻ sys_close ↻ sys_fork rg_child fl_acquire fl_try fl_mkdir sys_mmap ↻ fl_path sys_openat_wr ↻ sys_flock sys_close ↻ fl_nap sys_mmap ↻ rg_read sys_openat_rd ↻ sys_mmap ↻ sys_read ↻ sys_close ↻ rg_nap_us sys_mmap ↻ rg_write ↻ fl_release

structs

none

consts

15const RG_N: i64 = 4
16const RG_K: i64 = 100

functions

18func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 3: g_ng_rowmain calls 1: sys_write
19func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 }
called by 1: main calls 3: g_wsys_mmapsys_write
20func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" "); g_w(id); g_w(": "); if ok==1 { g_w("OK\n"); pass[0]=pass[0]+1 } else { g_w("FAIL\n") } return 0 }
called by 1: main calls 1: g_w
22func rg_nap_us(us: i64) -> i64 { let ts: *i64 = sys_mmap(16) as *i64; ts[0]=0; ts[1]=us*1000; __syscall(35, ts as i64, 0, 0, 0, 0, 0); return 0 }
called by 1: rg_child calls 1: sys_mmap
25func rg_read(path: *u8) -> i64
36func rg_write(path: *u8, v: i64) -> i64
46func rg_child(path: *u8, lock_res: *u8, locked: i64) -> i64
62func rg_phase(path: *u8, lock_res: *u8, locked: i64) -> i64
76func main() -> i64