threads(M6): getCurrentId, docs, and CI wiring — threading built
New thread_self=42 syscall backs runtime.Thread.getCurrentId (the calling thread's kernel task id). thread-test gains an id mode: two workers read getCurrentId and the main thread confirms all three ids are non-zero and distinct. Per-thread threadlocal TLS is deferred by design (no consumer; it would need context-switched fs.base for an unused feature), as are RwLock/WaitGroup. Marks the threading feature built (M1-M6): threading.md + docs/README.md status updated, all thread-* cases wired into qemu_test.py. Gate thread-id PASS; full suite green: 21/21 (thread-spawn/join/futex/mutex/id, aspace-refcount, + 15 guardrail cases), zig build clean, zig build test green.
This commit is contained in:
+30
-12
@@ -240,20 +240,38 @@ green.
|
||||
> `thread-mutex` gate exercises them under real concurrency instead; a host-side mock is
|
||||
> future work.
|
||||
|
||||
## M6 — TLS, `getCurrentId` polish, docs, and CI wiring
|
||||
## M6 — `getCurrentId`, docs, and CI wiring ✅
|
||||
|
||||
- [ ] Per-thread TLS: `thread_spawn` sets `fs.base` to a runtime-allocated per-thread
|
||||
block; enough for `getCurrentId` and a `threadlocal` slot. Only expanded if a
|
||||
consumer needs full `threadlocal`.
|
||||
- [ ] `RwLock` / `WaitGroup` if a consumer wants them (else deferred).
|
||||
- [ ] All `thread-*` cases wired into [test/qemu_test.py](../test/qemu_test.py);
|
||||
threading.md status line updated to "built"; a short worked example in the doc.
|
||||
- [ ] `-Dtest-case=thread-tls`: two threads read `getCurrentId` (distinct) and each
|
||||
writes its own `threadlocal` slot without cross-talk.
|
||||
- [x] `getCurrentId` via a small `thread_self = 42` syscall (`runtime.Thread.getCurrentId`
|
||||
returns the kernel task id). **Per-thread `threadlocal` TLS is deferred** — no
|
||||
consumer needs it, and it would require context-switching `fs.base` per task (real
|
||||
kernel + per-switch cost) for an unused feature; threaded binaries have run fine
|
||||
without it through M2–M5. threading.md's TLS reasoning already scoped it as
|
||||
deferred-unless-needed. When a consumer appears, the shape is: `thread_spawn`
|
||||
allocates a per-thread TLS block, sets `fs.base`, and the context switch saves/
|
||||
restores it.
|
||||
- [x] `RwLock` / `WaitGroup` deferred (no consumer yet); they slot onto the same
|
||||
`Futex`/`Mutex`/`Condition` when wanted.
|
||||
- [x] All `thread-*` cases wired into [test/qemu_test.py](../test/qemu_test.py)
|
||||
(`thread-spawn`/`-join`/`-futex`/`-mutex`/`-id`); threading.md + docs/README.md
|
||||
status updated to **built**; the worked example is threading.md's win-condition.
|
||||
- [x] `-Dtest-case=thread-id` (`smp: 4`): two workers read `getCurrentId`; the main
|
||||
thread confirms all three ids are non-zero and distinct — each thread has its own
|
||||
kernel identity. (Renamed from `thread-tls`, which implied `threadlocal`.)
|
||||
|
||||
**Gate:** `python3 test/qemu_test.py thread-tls` logs `thread: per-thread id + tls ok`;
|
||||
the whole `thread-*` suite plus the full guardrail set pass; default `zig build` is
|
||||
clean and `zig build test` is green.
|
||||
**Gate (met):** `python3 test/qemu_test.py thread-id` passes; the whole `thread-*` suite
|
||||
(`thread-spawn`/`-join`/`-futex`/`-mutex`/`-id`) plus the full guardrail set pass; default
|
||||
`zig build` clean, `zig build test` green.
|
||||
|
||||
---
|
||||
|
||||
## Status: built
|
||||
|
||||
M1–M6 complete. danos has `runtime.Thread` — `spawn`/`join`/`detach`, cross-core
|
||||
parallelism, futex, and `Mutex`/`Condition`/`Semaphore`, all over a private thread ABI
|
||||
behind the runtime. Deferred (with rationale, no consumer yet): `threadlocal` TLS,
|
||||
`RwLock`/`WaitGroup`, kernel clear-on-exit for a futex-completion `join`, a per-aspace
|
||||
mmap arena / thread-safe runtime heap, and host-side unit tests via a mockable `Futex`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user