← board

i386 --threadsafe runtime locks (heap / ARC / I-O)

Context

The i386 threading MECHANISM is done and verified (2026-07-03): the __pxxclone int-0x80 trampoline (thread_emit.inc — note i386 clone's tls/ctid registers are swapped vs x86-64), IR_CLONE + 32-bit IR_ATOMIC codegen in ir_codegen386.inc, and the i386 syscall numbers in palthread.pas (mmap2/munmap/mprotect/futex/gettid). A 4-thread × 100k futex-mutex counter test ran exactly (400000) under qemu-i386 with the --threadsafe guard temporarily bypassed.

What remains is why the guard stays: under --threadsafe the i386 runtime would be silently UNLOCKED. The x86-64 pieces to port:

Acceptance

test_palthread / test_mutex / test_atomic_counter / test_tthread compile with --threadsafe --target=i386 and run exactly under qemu-i386; heap stress (concurrent GetMem/FreeMem + managed strings) clean; x86-64 self-host byte-identical.

Resolution (2026-07-03, Track A — same session as the split)

Design: instead of porting x86-64's codegen-site lock wrapping (~35 helper call sites in the 386 backend + epilogues), the locks live in PASCAL under a new compile-time define PXX_TS_SOFTLOCK (set by the lexer only for --threadsafe --target=i386, so the default build's lexing skips the regions and every other configuration is byte-identical):

Verified under qemu-i386 (all in make test-i386): test_palthread, test_mutex, test_atomic_counter, test_tthread, test_tthread_sync, and a new 4-thread × 20k GetMem/FreeMem + managed-string churn stress (test_threadsafe_i386_stress, 5/5 clean). Also green outside the gate: test_critsec_once, test_tthread_terminate, test_tthread_final, test_condvar on i386. x86-64 make test + test-threads green; self-host byte-identical.