Expand description
Phase II’s runtime: run the chains of one level of synchronous code on threads.
par_run runs its first job on the calling thread and the others on a persistent pool of
parked workers, and returns only when every job has finished. That is what lets the jobs borrow
from the caller’s stack frame, as std::thread::scope does, at about a tenth of its cost per
job (a parked worker is woken; no thread is created). The pool grows when every worker is busy,
so a job that blocks on I/O never waits for a worker that is itself waiting for it, and past
MAX_WORKERS a job runs on the calling thread instead.
The pool is separate from rayon’s on purpose: its workers block on I/O, and blocking in rayon’s CPU-sized pool would starve everything else that uses rayon.
Structs§
- Latch 🔒
- Counts unfinished jobs;
Latch::waitreturns when there are none. - Pool 🔒
- SendPtr 🔒
- A pointer that may cross threads:
par_runguarantees what it points to outlives the job. - Wait
OnDrop 🔒 - Waits for the pool’s jobs even if the caller’s own job panics, so no job outlives the borrows it was given.
Constants§
- MAX_
WORKERS - Past this many workers, jobs run on the thread that asked for them.
Functions§
- par_run
- Run every job, the first on this thread and the rest on the pool, and return when all have finished. A job that panics on a worker is caught there, and the panic is resumed here after every job has finished (psync’s generated jobs catch their own panics, to replay them in program order; this is the backstop).
- pool 🔒
Type Aliases§
- Job 🔒