Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: interrupt solvers and cancel futures for early termination (a16z…
…#243) The --early-exit flag is now properly handled to ensure that Halmos terminates immediately after finding the first counterexample, avoiding unnecessary solver computations. The previous implementation allowed solver threads to continue running even after a counterexample was found, leading to inefficient resource usage and delayed termination. The updated code introduces the following changes: - A global list `solver_contexts` is introduced to store the solver contexts created in the `solve` function. - The `solve` function is modified to append the solver context to the global list before returning. - The list of futures is stored in a variable before submitting them to the thread pool. - In the `future_callback` function, if `args.early_exit` is true and a counterexample is found: - All the solver contexts in the global list are interrupted using `ctx.interrupt()`. - The remaining futures are canceled using `future.cancel()` to stop unnecessary computations. - The global lists are cleared to prevent memory leaks. - Exception handling is added to the interruption process to avoid segmentation faults. With these changes, when `args.early_exit` is true and a counterexample is found, the `future_callback` function interrupts all the running solver contexts and cancels the remaining futures, effectively stopping the unnecessary computations and allowing Halmos to terminate early.
- Loading branch information