Skip to content

Avoid a couple theoretical reorderings in ManualResetValueTaskSourceCore#72657

Merged
stephentoub merged 1 commit intodotnet:mainfrom
stephentoub:mrvtscsync
Jul 27, 2022
Merged

Avoid a couple theoretical reorderings in ManualResetValueTaskSourceCore#72657
stephentoub merged 1 commit intodotnet:mainfrom
stephentoub:mrvtscsync

Conversation

@stephentoub
Copy link
Copy Markdown
Member

In a typical usage sequence, GetStatus is called and then GetResult is called. If the read of _result in GetResult could move to before the read of _continuation in GetStatus, then there could be a race condition where _result is read prior to it being written, then _continuation is set as part of the operation completing, and the implementation ends up returning an erroneous result. Similarly, in SignalCompletion, if the read of _continuationState could moved to before the first read of _continuation, it could be stale.

Closes #68623

In a typical usage sequence, GetStatus is called and then GetResult is called.  If the read of _result in GetResult could move to before the read of _continuation in GetStatus, then there could be a race condition where _result is read prior to it being written, then _continuation is set as part of the operation completing, and the implementation ends up returning an erroneous result.  Similarly, in SignalCompletion, if the read of _continuationState could moved to before the first read of _continuation, it could be stale.
@stephentoub stephentoub requested a review from kouvel July 22, 2022 02:11
@ghost ghost assigned stephentoub Jul 22, 2022
@ghost
Copy link
Copy Markdown

ghost commented Jul 22, 2022

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details

In a typical usage sequence, GetStatus is called and then GetResult is called. If the read of _result in GetResult could move to before the read of _continuation in GetStatus, then there could be a race condition where _result is read prior to it being written, then _continuation is set as part of the operation completing, and the implementation ends up returning an erroneous result. Similarly, in SignalCompletion, if the read of _continuationState could moved to before the first read of _continuation, it could be stale.

Closes #68623

Author: stephentoub
Assignees: -
Labels:

area-System.Threading

Milestone: -

@stephentoub stephentoub added this to the 7.0.0 milestone Jul 24, 2022
@stephentoub
Copy link
Copy Markdown
Member Author

@kouvel or @mangod9, could you help review this?

@stephentoub stephentoub merged commit 3c25f59 into dotnet:main Jul 27, 2022
@stephentoub stephentoub deleted the mrvtscsync branch July 27, 2022 00:52
timcassell added a commit to timcassell/BenchmarkDotNet that referenced this pull request Jul 27, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synchronization in ManualResetValueTaskSourceCore is inconsistent with the memory model

2 participants