[GR-63549] Fix data race between swapOut and addPredicated in the TypeFlow class #10956
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.
When assignable
FilterTypeFlowandFieldFilterTypeFlowsaturate, they replace themselves with all instantiated typeflow of theirdeclaredType. The current ordering of operations allows for an interleaving, in which a new predicated flowfmay be added to already saturated filter flow, which will result infnever getting enabled.An example of a problematic execution
Thread
t1yields insideFilterTypeFlow.addPredicatedline 112 before calling super.FilterTypeFlow.onInputSaturatedgets executed on another threadt2, which will lead to callingswapOut, replacing this flow with thefilterType.t2yields after swapping all dependencies, but before marking predicate edge as triggered.t1continues, adds a new predicate to the previously cleared set, but since predicate edge was not marked as triggered yet, it won't enable the new flowf.t2continues, marks the predicate edge as triggered, but won't do anything withf, which was added to its set of predicated flows in the meantime. As a result, a saturated flow with triggered predicate edge will end up having a new predicated flow (which is stil disabled), but predicate edge will not trigger again.Solution
We change the order of swapping out predicate edges and marking predicate edge as triggered, making sure that any new concurrently added predicated flows will get enabled during the
super.addPredicatedcall.