Avoid a couple theoretical reorderings in ManualResetValueTaskSourceCore (#72657)
authorStephen Toub <stoub@microsoft.com>
Wed, 27 Jul 2022 00:52:40 +0000 (20:52 -0400)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2022 00:52:40 +0000 (20:52 -0400)
commit3c25f598599c6a204f1bece18cb87e8889ed7cfe
tree4c2eb051832b895cb2cf02a19520683ce3a87bb1
parent14ad0e1a47679d4a17c6f148df4397da3b5697d5
Avoid a couple theoretical reorderings in ManualResetValueTaskSourceCore (#72657)

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.
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs