-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a race condition in DTD for the local termdet #698
Merged
abouteiller
merged 4 commits into
ICLDisco:master
from
therault:fix/local-termdet-race-condition-for-dtd
Nov 17, 2024
Merged
Fix a race condition in DTD for the local termdet #698
abouteiller
merged 4 commits into
ICLDisco:master
from
therault:fix/local-termdet-race-condition-for-dtd
Nov 17, 2024
Conversation
This file contains 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
DTD uses termination_detected() to destroy the taskpool, and on_leave_wait() to reset the taskpool and reinitialize the termination detector. The 'local' termination detector module had a race condition: it would mark the taskpool as 'terminated', then call the termination_detected() callback. As any thread can detect the termination, a worker thread could enter taskpool destruction in parallel with the main thread calling on_leave_wait() because taskpool_state() has returned TERMINATED already. Thus, the taskpool could be destroyed *after* its termination detector is reset, leading to asserts. Proposed solution consists of adding an intermediary state in the termination detector, 'TERMINATING'. TERMINATING is shown as 'BUSY' to the scheduler, so the main thread does not return from the main loop and does not call on_leave_wait() while the thread that detected termination is still executing termination_detected(). TERMINATING is still a necessary intermediary step in order to ensure that only one thread calls termination_detected(). Solves issue ICLDisco#634
abouteiller
approved these changes
Nov 13, 2024
devreal
reviewed
Nov 13, 2024
devreal
approved these changes
Nov 13, 2024
QingleiCao
approved these changes
Nov 13, 2024
…eeping the taskpool alive until the termination detector is done doing its things. To do this, the termination detector keeps a reference on the taskpool, until it is effectively terminated. Taskpool destruction can then be delayed until termination completes.
…t the taskpool release within the termination detector doesn't cycle calling the destructor again
termination detector has been removed manually) to be unregistered.
abouteiller
reviewed
Nov 17, 2024
passed ctests |
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.
DTD uses termination_detected() to destroy the taskpool, and on_leave_wait() to reset the taskpool and reinitialize the termination detector.
The 'local' termination detector module had a race condition: it would mark the taskpool as 'terminated', then call the termination_detected() callback.
As any thread can detect the termination, a worker thread could enter taskpool destruction in parallel with the main thread calling on_leave_wait() because taskpool_state() has returned TERMINATED already.
Thus, the taskpool could be destroyed after its termination detector is reset, leading to asserts.
Proposed solution consists of adding an intermediary state in the termination detector, 'TERMINATING'. TERMINATING is shown as 'BUSY' to the scheduler, so the main thread does not return from the main loop and does not call on_leave_wait() while the thread that detected termination is still executing termination_detected(). TERMINATING is still a necessary intermediary step in order to ensure that only one thread calls termination_detected().
Solves issue #634