1# @ajax/mesh-driver
23meshd's driver thread: the only ring publisher and program-table writer; lifecycle, blinks, publishing, pipes and job items.
45meshd's driver thread (driver.rs).
67The only publisher of every ring and the only writer of the program table. Each tick it collects completions, honours run requests and commands, and publishes the next tasks of every loaded program -- each its own resident kernel (or wasm lanes, or a native worker) with its own ring.
89Lifecycle (plan §3.1): start/stop launch or halt one program's kernel and touch nothing else (zero gap). Anything that changes the context's module set (load, upgrade, unload --now) is a *blink*, because module loads and unloads block while any kernel of the context runs: drain every ring, halt every kernel, do the module operations (images compiled beforehand on a worker thread), rewind each ring head to its published tail, launch everything that runs, then wait for all of it. Rollback and reset need no module operation: they blink only their slot. Isolated executors (mps, the CPU executors) blink only the slot a module change touches.
1011Executors are per slot (mesh-abi PX_EXEC): the GPU backend and beside it the CPU executors (wasm lanes, native worker processes). A load runs on the first executor its manifest's `backends` lists that this meshd has.
1213```c
14#include "mesh/driver.h"
15```
1617## Ported from
1819[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) (Richard Safier, MIT): crates/mesh-host/src/driver.rs (all of it: `Config`, `Job`, `Op`, `Blink`, `Waiter`, `Zombie`, `GoneInbox`, `DeadCell`, `JLease`, `JobSlot`, `SetupState`, `Driver` and every method), and programs.rs `Image`, `Phase`, `Slot`, `view_compatible`.
2021## Tests
2223- `tests/driver.c`: driver.rs's `job_setup_in_order` and `reads_by_name`; and the driver end to end over a fake CPU executor whose nodes are a thread playing mesh-rt's node loop: autoload (and a program it may not run), the blink, OP_INIT, tasks, refusals, stop and start, reset, `--state`, unload and load into the freed slot, shutdown.
24- `tests/place.c`: placement over the fake executor, peered (member 0 of 2) with a placeable program: the `place` report, a pin asked of the leader, the refusal as a follower, the leader's PL_SET pinning it elsewhere (its state written into the view, its kernel stopped, start and reset refused, input forwarded as F_INPUT, PL_DONE answered, the inventory counting it run), back to local, unload.
25- apps/meshd's tests run it with the real wasm and native executors, single and as a fleet of three.
2627## Placement
2829- **Placement** is the fleet area's @ajax/mesh-placer, one per placeable program when peered (`src/place.c`: driver.rs's `sync_place`, `place_acts`, `apply_mode`, `place_tick`, `place_frame` and the role checks in `publish_slot`, ProgRun, Reset, run requests and Input).
30- The JIT runs one detached thread per load or upgrade, as the Rust's `std::thread::spawn`.
3132## Licence
3334MIT. See the repository's LICENSE.