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 for early termination with --early-exit (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. - 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()`. - Exception handling is added to the interruption process to avoid segmentation faults. - After interrupting the solvers, the global list is cleared to prevent memory leaks. With these changes, when `args.early_exit` is true and a counterexample is found, the `future_callback` function interrupts all the running solver contexts, effectively stopping the unnecessary computations and allowing Halmos to terminate early.
- Loading branch information