Accord.InterlockedEx.Increment C# (CSharp) Method

Increment() public static method

Increments a specified variable and stores the result, as an atomic operation.
public static Increment ( double &location1 ) : double
location1 double The variable to be incremented.
return double
        public static double Increment(ref double location1)
        {
            double newCurrentValue = 0;
            while (true)
            {
                double currentValue = newCurrentValue;
                double newValue = currentValue + 1;
                newCurrentValue = Interlocked.CompareExchange(ref location1, newValue, currentValue);
                if (newCurrentValue == currentValue)
                    return newValue;
            }
        }
    }
InterlockedEx