KRN-THR requirements¶
At most one thread shall be in the RUNNING state on each online logical processor. Rationale: Definition of the scheduler’s invariant. Status: Accepted 2026-10-07 Verification: Analysis: model invariant ( Trace: SPEC-008 §1; 03 §1.1; v0.1 §3.3 |
A READY thread shall be eligible for scheduling. Rationale: State definition. Status: Accepted 2026-10-07 Verification: Analysis: model invariant 5 of SPEC-004 §5.4. Trace: SPEC-008 §1 |
A BLOCKED thread shall not be eligible for scheduling. Rationale: State definition. Status: Accepted 2026-10-07 Verification: Analysis: model invariant 5. Trace: SPEC-008 §1 |
Each normal thread shall possess an independent execution context and stack. Rationale: Preemptive multithreading. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §4, §10 |
Returning from a thread entry function shall cause controlled thread termination through the kernel. Rationale: No fall-off-the-end crash. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §4, §5 |
Thread execution lifetime and thread-object lifetime shall be independent. Rationale: The exit code and the storage outlive execution; the object can exist before start. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §1, §5, §6, §8 |
The kernel shall support statically allocated threads without requiring a dynamic allocator. Rationale: KRN-MEM-001; the tiny profile. Status: Accepted 2026-10-07 Verification: Analysis: Trace: SPEC-008 §2, §4 |
Thread identity shall remain stable for the lifetime of the thread object. Rationale: Handles and debugger views. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §3, §8 |
Thread start, suspend, and resume shall be expressed through the common wait mechanism as wait reasons, not as additional scheduler states. Rationale: One protocol (SPEC-004). Status: Accepted 2026-10-07 Verification: Analysis: Trace: SPEC-008 §4, §7; SPEC-004 §6.5 |
A suspended thread shall retain any pending object wait and its deadline; resume shall re-enter that wait without losing the thread’s wait-queue position relative to later waiters. Rationale: Removes the classic suspend-while-waiting ambiguity. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §7; KRN-WAIT-014 |
Thread cancellation shall be cooperative: a cancel request is delivered as a wake result at the next blocking call or explicit cancellation point; threads are never asynchronously killed. Rationale: Asynchronous kills leave locks and buffers in undefined states. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §5, §7; KRN-WAIT-015 |
Join shall be supported for joinable threads; a detached thread’s object storage becomes reusable immediately on termination according to its storage policy. Rationale: POSIX-shaped lifetime control without an allocator. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §6 |
Thread-local storage slots shall be available as a compile-time option with a fixed per-thread slot count. Rationale: Per-thread state for libraries without compiler TLS. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §9 |
The kernel, ports, and drivers shall not use compiler thread-local storage ( Rationale: Toolchain constraint. Status: Accepted 2026-10-07 Verification: Analysis: CI grep for Trace: SPEC-008 §9; 09 §3 |
A thread object shall pass through Rationale: A defined reuse point instead of idle-task reclamation (R-001 §1, FreeRTOS) or a spin on in-flight timeouts (Zephyr). Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §5, §8 |
Rationale: One way to begin execution; no implicit start at init. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §4 |
Termination shall release owned mutexes per Rationale: Deterministic teardown order that other specifications can rely on. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §5 |
Exactly one thread may join a given thread ( Rationale: One-slot join is O(1) and unambiguous. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §6 |
Rationale: Lifetime control for fire-and-forget threads. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §6 |
Rationale: Counting suspends are a classic source of stuck threads. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §7, §11 |
A cancel request shall wake a blocked cancelable wait at once when cancellation is enabled, otherwise be delivered at the next cancellation point; delivery shall clear the request; a per-thread disable count (bounded at 255) shall defer delivery while nonzero; Rationale: Threads need regions where cancellation cannot interrupt a protocol. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §7 |
Larger numeric values shall mean higher priority; Rationale: v0.1 §3.5; consistency with the interrupt numbering of SPEC-002 §8. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §1, §3; SPEC-005 §2.3 |
Thread stacks shall be caller-provided, aligned to Rationale: KRN-MEM-009, 010, 011 applied to threads. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §10; KRN-MEM-009 to 011 |
Rationale: KRN-OBJ-001 to 003 for threads. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §8 |
The kernel shall report a thread’s state and wait reason, name, stable index, base and effective priority, and (optionally) stack usage, and shall offer Rationale: Tooling and statistics. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §3, §13 |
The idle thread and work queue threads shall be kernel threads: not suspendable, cancelable, joinable, or re-prioritizable by the application ( Rationale: The kernel’s own progress must not depend on application calls. Status: Accepted 2026-10-07 Verification: Test: Trace: SPEC-008 §11 |
A thread shall belong to one partition; an unprivileged partition shall create threads only in itself, from storage in its own region, before freeze; cross-partition thread operations shall require the corresponding right on a thread capability. Rationale: KRN-PART-001, ADR-033, SPEC-009. Status: Accepted 2026-10-07 Verification: Isolated-profile tests Trace: SPEC-008 §4; KRN-PART-001, 007; KRN-CAP-002 |
Init, start, exit with code, join, suspend, resume, cancel, priority change, and destroy shall be trace events; CPU time, switch count, blocked time, and stack high-water shall be optional per-thread statistics. Rationale: 04 §7.5. Status: Accepted 2026-10-07 Verification: Test: trace decoder; statistics API test. Trace: SPEC-008 §13 |
With the table scheduler a thread’s slot shall be its unique priority, up to 16 threads including idle; Rationale: ADR-036; targets T1 and T2. Status: Accepted 2026-10-07 Verification: Footprint test of the tiny reference configuration; Trace: SPEC-008 §14 |
The reference model shall include start of inactive threads, join with exit-code hand-off and the one-joiner rule, explicit exit codes, and shall be explored over join before and after exit, join with timeout, cancellation of a joiner, start by another thread, and exit while owning a mutex. Rationale: Lifecycle races are protocol races. Status: Accepted 2026-10-07 Verification: Analysis: Trace: SPEC-008 §15; KRN-WAIT-007 |