0102: Worker arenas, thread-local arena tables and result adoption
Status: Proposed (default; pending owner confirmation)
Extends ADR-0036, ADR-0037, ADR-0045 and ADR-0061.
Context
Workers need isolated allocation while immutable inputs are shared, and their results must survive joining without unsafe sharing of mutable arena state.
Decision
Thread support is enabled only for programs using
Par, via HN_PAR and
-pthread, with the flag included in the build-cache
key. A lazy persistent pool uses 8 MiB worker stacks;
HRT_THREADS selects the count, defaulting to online
processors, capped at 64. Invalid values use the default; one
thread runs inline. The caller participates and workers claim
chunks dynamically.
Arena tables, persistent state and read errno are thread-local
under HN_PAR; shared accounting is atomic and lazy
initializers run before dispatch. Workers allocate results in
fresh per-call arenas. After join the caller adopts arena records
through destination-arena hrt_cleanup; workers reset
their slots. If region checks make adoption unsuitable, copy
results back and record the copies; M11.1 tests decide whether
this fallback is needed.
Consequences
Nonparallel emitted C remains byte-identical and does not require pthreads. Adoption ties result lifetimes to the destination arena; its safety and the fallback require focused region and runtime tests.