Harden thread/async robustness in optimize and formatters#383
Open
HamzaYslmn wants to merge 1 commit into
Open
Harden thread/async robustness in optimize and formatters#383HamzaYslmn wants to merge 1 commit into
HamzaYslmn wants to merge 1 commit into
Conversation
fontanf
reviewed
Jun 14, 2026
|
|
||
| // Take a snapshot of the output so the (potentially heavy, file-I/O | ||
| // performing) callback can run outside the critical section. | ||
| output_snapshot = output_; |
Owner
There was a problem hiding this comment.
This copy is not ideal. The output structure might be large. It will slow down the solver for instances where many solutions are found. The solution I see is to handle I/O issues in the callback directly. Let me know if you see a better alternative
- Move new_solution_callback (file I/O) out of the formatter mutex critical section by snapshotting the output under the lock and invoking the callback after unlocking, so worker threads no longer serialize on the callback's disk writes. - Convert manual mutex_.lock()/unlock() in all update_* methods to RAII std::unique_lock for exception safety (no deadlock if a callback throws). - Add a ThreadJoinGuard RAII helper and place it after every worker-thread vector so threads are joined during stack unwinding instead of triggering std::terminate() if an exception is thrown before the explicit join loop.
a697525 to
c9218ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens thread and async handling across the optimize entry points and algorithm formatters (box, boxstacks, irregular, onedimensional, rectangle, rectangleguillotine) to avoid races and lost results under concurrency.