Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs
index 3fa2f71ade7..e700a1fb8a5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs
@@ -528,13 +528,11 @@ namespace System.Collections.Concurrent
// If the expected sequence number is not yet written, we're still waiting for
// an enqueuer to finish storing it. Spin until it's there.
- if ((segment._slots[i].SequenceNumber & segment._slotsMask) != expectedSequenceNumberAndMask)
+ SpinWait spinner = default;
+ // Must read SequenceNumber before reading Item, thus Volatile.Read
+ while ((Volatile.Read(ref segment._slots[i].SequenceNumber) & segment._slotsMask) != expectedSequenceNumberAndMask)
{
- SpinWait spinner = default;
- while ((Volatile.Read(ref segment._slots[i].SequenceNumber) & segment._slotsMask) != expectedSequenceNumberAndMask)
- {
- spinner.SpinOnce();
- }
+ spinner.SpinOnce();
}
// Return the value from the slot.