Accord.InterlockedEx.Add C# (CSharp) Method

Add() public static method

Adds two 32-bit floating point values and replaces the first double value with their sum, as an atomic operation.
public static Add ( double &location1, double value ) : double
location1 double The first variable to be added.
value double The second variable to be added.
return double
        public static double Add(ref double location1, double value)
        {
            double newCurrentValue = 0;
            while (true)
            {
                double currentValue = newCurrentValue;
                double newValue = currentValue + value;
                newCurrentValue = Interlocked.CompareExchange(ref location1, newValue, currentValue);
                if (newCurrentValue == currentValue)
                    return newValue;
            }
        }
InterlockedEx