Skip to main content

Module interrupt

Module interrupt 

Source
Expand description

Cooperative interruption of long-running orderings (feral issue #246).

An Interrupt carries an optional wall-clock deadline and an optional cancel flag. scope installs one for the duration of a closure on the current thread. Long-running loops in the ordering crates call poll or check at safe points (between pivots, levels, trials and passes) with no change to their signatures.

Single-thread assumption. A thread-local is sound here because every ordering in this family (feral-amd, -amf, -metis, -scotch, -kahip), and feral’s symbolic pipeline and MC64 matching, run entirely on the thread that called scope. If any of them ever moves work onto rayon or spawned threads, polls on those workers see no active interrupt, and the deadline silently stops working there. Code that goes parallel must capture the interrupt with current and re-install it on each worker with scope. Each ordering crate has a tests/interrupt_threads.rs that uses the census to fail if an ordering polls from a thread with no scope while its caller has one, so such a change cannot slip in unnoticed.

Sticky. Once a poll inside a scope has seen the interrupt trigger, every later poll in that scope reports it, even if the flag is cleared. A loop that breaks out early on poll can therefore rely on the next check up the stack returning OrderingError::Interrupted, so a partially computed intermediate is never used as a result.

With no interrupt installed, a poll costs one thread-local read.

Modules§

census
Opt-in poll census for tests that guard the single-thread assumption (PR #247 review).

Structs§

Interrupt
A deadline and/or a cancel flag. Interrupt::default() never triggers.

Functions§

check
Err(OrderingError::Interrupted) when poll is true.
current
The interrupt active on this thread, if any. Parallel code captures it here and re-installs it on each worker with scope (see the module docs on the single-thread assumption).
is_active
True when an interrupt that can trigger is active on this thread.
poll
True when the active interrupt has triggered (sticky within its scope). With no active interrupt, returns false.
scope
Run f with interrupt active on this thread, then restore whatever was active before (also on panic). An inert interrupt still opens a scope, which shields f from an outer interrupt; use scope_if to keep the outer one.
scope_if
scope when interrupt is Some, otherwise run f under whatever is already active.