public static double Add(ref double location1, double value)
double newCurrentValue = location1;
double currentValue = newCurrentValue;
double newValue = currentValue + value;
newCurrentValue = Interlocked.CompareExchange(ref location1, newValue, currentValue);
if (newCurrentValue == currentValue)
public static void Main()
Console.WriteLine(Add(ref d1, 2));