Expand description
psync: automatic concurrency for async Rust, and a small priority executor.
graph(#[psync::graph]) rewrites an async function so that awaits which do not depend on each other run concurrently, with results, errors, early exits and writes to files and services kept as in the sequential code. The hintsseq,fresh,independentandspeculatetell it what tokens cannot show. The generated code needs onlycoreandalloc(loop fission also usesstd’sVec) and runs on any executor.Executoris a cooperative, single-core,no_stdexecutor: larger priorities run first, equal priorities rotate FIFO, and sleeping tasks are polled only after a wake.
The psync book (book/ in the repository) covers both in depth.
Modules§
- executor 🔒
- files 🔒
- File identity for
#[psync::graph(owned_files)]: two paths name one file when the operating system says so, not when their text matches. - future 🔒
- multi 🔒
- A multi-threaded, priority-aware executor (feature
std). - os 🔒
- par 🔒
- Phase II’s runtime: run the chains of one level of synchronous code on threads.
- park 🔒
- pool 🔒
- profile
- Traces for
psync-predict, from functions annotated#[psync::graph(profile)]. - task 🔒
Structs§
- Default
Park - Uses WFE/SEV on RP2350 ARM, and spins on other targets.
- Default
Pool - Executor
- Cooperative executor for local futures; keep it on one core. Higher numbers run first. A continuously ready high-priority task can starve lower priorities.
- Multi
Executor - A priority-aware executor running
Sendfutures on worker threads. - Multi
Handle - Changes the priority of, wakes, or checks a task of a
MultiExecutor. - Task
- A scheduled future, owned by its executor’s pool.
- Task
Handle - Changes priority and wakes a task. Handles never contain the task’s local future.
- Yield
Now - The future returned by
yield_now.
Traits§
- Park
- Parking must preserve an unpark notification delivered just before park.
- Pool
- A local task queue.
take_readymust remove the highest-priority ready task.
Functions§
- in_
flight_ beyond_ first - How many loop items beyond each loop’s first are in flight now: the budget’s tokens in use.
- set_
in_ flight_ budget - Limit how many prefetched loop items may be in flight at once across the whole process, beyond the first item of each loop.
- yield_
now - Returns
Pendingonce (after waking itself), letting the executor run other ready tasks. Works on any executor.#[psync::graph(yield_every = N)]inserts it into long loops.
Type Aliases§
Attribute Macros§
- fresh
- Hint on a
let: each concurrent branch that uses this binding evaluates its initializer again instead of sharing the value, e.g.#[psync::fresh] let pool = &mut context.pool();gives every branch its own pooled connection. Outside#[psync::graph], stable Rust rejects a custom attribute on a statement or expression (E0658): the graph macro removes it before the compiler sees it. - graph
- Build the function’s await dependency graph and run independent work concurrently.
- independent
- Hint on a
forloop: the programmer asserts that an iteration’s awaited work does not depend on what earlier iterations wrote, so psync may run it ahead even where it cannot prove that. On a statement: its effects on outside resources commute with those of the statements around it (two writes to different objects through one client), so they need not keep their order. - par
- Hint on a statement of a synchronous
#[psync::graph]function: it is worth a thread (a slow call psync cannot recognize by its path, such as a helper that downloads a file). psync may then run it on another thread beside independent statements. Outside a synchronous#[psync::graph]function it has no effect, and on a statement it does not compile (E0658). - seq
- Hint: keep this statement in its original position inside a
#[psync::graph]function. Outside one, stable Rust rejects a custom attribute on a statement or expression (E0658): the graph macro removes it before the compiler sees it. - speculate
- Hint on a statement or
forloop: its writes (to files, services, the network) may run ahead of an earlier?,returnorbreak, or for later loop items before an earlier item ends the loop. The programmer asserts that performing them when sequential code would not have is harmless (idempotent uploads, cache fills). Outside#[psync::graph], stable Rust rejects a custom attribute on a statement or expression (E0658): the graph macro removes it before the compiler sees it.