Skip to main content

Crate psync

Crate psync 

Source
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 hints seq, fresh, independent and speculate tell it what tokens cannot show. The generated code needs only core and alloc (loop fission also uses std’s Vec) and runs on any executor.
  • Executor is a cooperative, single-core, no_std executor: 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§

DefaultPark
Uses WFE/SEV on RP2350 ARM, and spins on other targets.
DefaultPool
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.
MultiExecutor
A priority-aware executor running Send futures on worker threads.
MultiHandle
Changes the priority of, wakes, or checks a task of a MultiExecutor.
Task
A scheduled future, owned by its executor’s pool.
TaskHandle
Changes priority and wakes a task. Handles never contain the task’s local future.
YieldNow
The future returned by yield_now.

Traits§

Park
Parking must preserve an unpark notification delivered just before park.
Pool
A local task queue. take_ready must 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 Pending once (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§

BoxFuture
LocalBoxFuture

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 for loop: 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 for loop: its writes (to files, services, the network) may run ahead of an earlier ?, return or break, 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.