diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs index 1cd82352ae175..e238c5b8d834c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs @@ -37,6 +37,9 @@ internal sealed class ConcurrentQueueSegment internal ConcurrentQueueSegment? _nextSegment; // SOS's ThreadPool command depends on this name #pragma warning restore 0649 + /// Threshold to spin before allowing threads to sleep when there is contention. + private const int Sleep1Threshold = 8; + /// Creates the segment. /// /// The maximum number of elements the segment can contain. Must be a power of 2. @@ -183,7 +186,7 @@ public bool TryDequeue([MaybeNullWhen(false)] out T item) } // Lost a race. Spin a bit, then try again. - spinner.SpinOnce(sleep1Threshold: -1); + spinner.SpinOnce(Sleep1Threshold); } } @@ -244,7 +247,7 @@ public bool TryPeek([MaybeNullWhen(false)] out T result, bool resultUsed) } // Lost a race. Spin a bit, then try again. - spinner.SpinOnce(sleep1Threshold: -1); + spinner.SpinOnce(Sleep1Threshold); } } @@ -301,7 +304,7 @@ public bool TryEnqueue(T item) } // Lost a race. Spin a bit, then try again. - spinner.SpinOnce(sleep1Threshold: -1); + spinner.SpinOnce(Sleep1Threshold); } }