System.Threading.Thread.VolatileRead C# (CSharp) Метод

VolatileRead() публичный статический Метод

public static VolatileRead ( System &address ) : System.IntPtr
address System
Результат System.IntPtr
        public static System.IntPtr VolatileRead(ref System.IntPtr address)
        {
            throw null;
        }

Same methods

Thread::VolatileRead ( System &address ) : System.UIntPtr
Thread::VolatileRead ( byte &address ) : byte
Thread::VolatileRead ( double &address ) : double
Thread::VolatileRead ( float &address ) : float
Thread::VolatileRead ( int &address ) : int
Thread::VolatileRead ( long &address ) : long
Thread::VolatileRead ( object &address ) : object
Thread::VolatileRead ( sbyte &address ) : sbyte
Thread::VolatileRead ( short &address ) : short
Thread::VolatileRead ( uint &address ) : uint
Thread::VolatileRead ( ulong &address ) : ulong
Thread::VolatileRead ( ushort &address ) : ushort

Usage Example

Пример #1
0
        public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
        {
            CheckState();
            if (millisecondsTimeout < -1)
            {
                throw new ArgumentOutOfRangeException("millisecondsTimeout",
                                                      "millisecondsTimeout is a negative number other than -1");
            }

            Watch sw = Watch.StartNew();

            Func <bool> stopCondition = () => millisecondsTimeout >= 0 && sw.ElapsedMilliseconds > millisecondsTimeout;

            do
            {
                bool shouldWait;
                int  result;

                do
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (stopCondition())
                    {
                        return(false);
                    }

                    shouldWait = true;
                    result     = currCount;

                    if (result > 0)
                    {
                        shouldWait = false;
                    }
                    else
                    {
                        break;
                    }
                } while (Interlocked.CompareExchange(ref currCount, result - 1, result) != result);

                if (!shouldWait)
                {
                    if (result == 1)
                    {
                        handle.Reset();
                    }
                    break;
                }

                SpinWait wait = new SpinWait();

                while (Thread.VolatileRead(ref currCount) <= 0)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (stopCondition())
                    {
                        return(false);
                    }

                    if (wait.Count > spinCount)
                    {
                        int timeout = millisecondsTimeout < 0 ? deepSleepTime :
                                      Math.Min(Math.Max(millisecondsTimeout - (int)sw.ElapsedMilliseconds, 1), deepSleepTime);
                        handle.WaitOne(timeout);
                    }
                    else
                    {
                        wait.SpinOnce();
                    }
                }
            } while (true);

            return(true);
        }