Fix a race in counting running tasks. #16607
Merged
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.
In the runtime's pre-user-code hook we force the running task counts to
the proper values after module initialization is done, because (for
reasons we need not go into here) that phase can leave the counts
incorrect but we need them to be correct when we embark on the user
program. We also set up memory tracking in that hook, because we don't
want to track memory during module init but we do want to track it (if
doing so is requested) in the user code. But this has a race with the
running task count setting, due to on-stmts from non-0 nodes back to
node 0 to access the associated config const values. Here, add a
barrier between the running task count reset and the memory tracking
setup to resolve this race.
While here, improve the commentary that describes why the pre-user-code
hook is the way it is.