System.Threading.Helpers.Spin C# (CSharp) Method

Spin() static private method

static private Spin ( int iterations ) : void
iterations int
return void
        internal static void Spin(int iterations)
        {
            RuntimeThread.SpinWait(iterations);
        }

Usage Example

Beispiel #1
0
        private void EnterMyLockSpin()
        {
            int pc = Environment.ProcessorCount;

            for (int i = 0; ; i++)
            {
                if (i < LockSpinCount && pc > 1)
                {
                    Helpers.Spin(LockSpinCycles * (i + 1)); // Wait a few dozen instructions to let another processor release lock.
                }
                else if (i < (LockSpinCount + LockSleep0Count))
                {
                    Helpers.Sleep(0);   // Give up my quantum.
                }
                else
                {
                    Helpers.Sleep(1);   // Give up my quantum.
                }

                if (_myLock == 0 && Interlocked.CompareExchange(ref _myLock, 1, 0) == 0)
                {
                    return;
                }
            }
        }
All Usage Examples Of System.Threading.Helpers::Spin