Skip to main content

Module executor

Module executor 

Source
Expand description

The work-stealing M:N native driver (Phase 7 of work/FINISH_INTERPRETER.md).

Genuine multicore for the VM/tree-walker tiers, native-only (std::thread + std::sync; never tokio, never crossbeam — this crate is dependency-free by charter). The design turns on one fact: a task body (Vm/Interpreter) holds Rc heaps and is irreducibly !Send, so tasks never cross threads. What crosses is only a Send descriptor; each worker builds its !Send task locally from its own clone of the program.

§Architecture — a central coordinator owns every decision

       ┌───────────────────────────────────────────┐
       │ Coordinator (the authoritative Scheduler + │
       │   the SINGLE Chooser seed choke point):    │
       │   channels, timers, the work deque         │
       └───────────────┬───────────────────────────┘
         Send descriptors ↓   ↑ Send StepReport
       ┌─────────────────┴──┐ ┌┴────────────────────┐
       │ Worker 0 (thread)  │ │ Worker N-1          │
       │  own program clone │ │  own program clone  │
       │  builds !Send task │ │  builds !Send task  │
       │  polls body → block│ │  polls body → block │
       └────────────────────┘ └─────────────────────┘

Workers never touch channels, timers, or the Chooser directly: they poll a task body (the expensive part — arithmetic, loops, JIT regions) and report the resulting StepReport back. The coordinator applies every report through the same crate::scheduler::Scheduler state machine and the same Chooser, in a deterministic order, so for a fixed seed the trace is identical to the cooperative run — parallelism only reorders the wall-clock arrival of reports, which a logical clock + a TaskId-sorted apply order erase.

Determinism is therefore preserved by construction: there is one choice point. “Spawns are stealable; resumptions are pinned” — a freshly spawned task (just (func, args)) can be built by any idle worker, but an already-built !Send continuation stays on the worker that last ran it.

Structs§

SpawnDesc
A Send task descriptor: which function to run, its already-materialised arguments, its scheduling priority, and whether it is the run’s main task. This is what a worker turns into a !Send task body locally.
WsOutcome
The result of a work-stealing run.

Enums§

ResumeKind
How a worker should (re)enter a task body on its next poll. Every variant is Send (FuncIdx is u16, RtPayload is Send, ids are Copy).

Functions§

run_workstealing_seeded
Run a concurrent program on the work-stealing M:N driver under seed.

Type Aliases§

FuncIdx
An opaque function index, from the runtime’s view — the compile crate’s FuncIdx (a u16), kept local so this crate stays dependency-free.