8000 Synchronize in-flight call draining on Exec.Finalize (fixes #470) by janpfeifer · Pull Request #471 · gomlx/gomlx · GitHub
[go: up one dir, main page]

Skip to content

Synchronize in-flight call draining on Exec.Finalize (fixes #470) - #471

Merged
janpfeifer merged 2 commits into
mainfrom
issue470
Oct 14, 2026
Merged

janpfeifer merged 2 commits into
mainfrom
issue470

Conversation

@janpfeifer
Copy link
Copy Markdown
Contributor

This PR resolves #470 by synchronizing in-flight execution and compilation draining when Finalize() is called on graph.Exec and model.Exec.

Changes

  • graph.Exec:
    • Added finalized atomic.Bool and muInFlight sync.RWMutex to coordinate execution draining with teardown.
    • Exported ErrExecFinalized, returned with stack-trace whenever operations are attempted on a finalized executor.
    • In Compile and compileAndExecute (which backs Call, CallWithGraph, MustCall, etc.):
      • Fast-fail immediately if finalized.Load() is true.
      • Acquire muInFlight.RLock(); defer muInFlight.RUnlock().
      • Double-check finalized.Load() to catch straddlers.
    • In Finalize():
      • Atomically mark finalized via Swap(true) (idempotent for multiple calls).
      • Acquire muInFlight.Lock(), ensuring all in-flight calls and compilations finish before releasing cached graphs.
  • model.Exec:
    • Added matching finalized atomic.Bool and muInFlight sync.RWMutex to protect model execution, variable collection, and compilation.
    • Exported model.ErrExecFinalized (aliased to graph.ErrExecFinalized).
  • Documentation:
    • Documented graph.Graph.Finalize() regarding caller responsibility for in-flight executions.
    • Documented lifecycle and concurrency guarantees in Exec and Finalize().
    • Added entry to docs/CHANGELOG.md.
  • Tests:
    • Added comprehensive TestExecFinalize test suites in both core/graph and ml/model covering basic idempotent finalization, deterministic concurrent call draining, deterministic concurrent compilation draining, and race stress testing across all backends.

Fixes #470.

… model.Exec.

Documented the lower-level graph.Finalize() that the user is responsible for waiting for all executions to finish.

See discussion in issue #470.
@janpfeifer
janpfeifer merged commit a72f7a6 into main Oct 14, 2026
4 checks passed
@janpfeifer janpfeifer self-assigned this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify the shutdown contract for Exec.Finalize

1 participant

0