code wiki / _hdl_build / nx_arbiter_race_gate.nx
nx_arbiter_race_gate.nx
buildroot/runtime/_hdl_build/nx_arbiter_race_gate.nx
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
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
structs
| none |
consts
| 15 | const RG_N: i64 = 4 |
| 16 | const RG_K: i64 = 100 |
functions
| 18 | func 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 } |
| 19 | func 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 } |
| 20 | func 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 } |
| 22 | func 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 } |
| 25 | func rg_read(path: *u8) -> i64 |
| 36 | func rg_write(path: *u8, v: i64) -> i64 |
| 46 | func rg_child(path: *u8, lock_res: *u8, locked: i64) -> i64 |
| 62 | func rg_phase(path: *u8, lock_res: *u8, locked: i64) -> i64 |
| 76 | func main() -> i64 |