DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.1.2" />

 AtomicReference

public static class AtomicReference
Provides atomic operations for the reference type.
public static T AccumulateAndGet<T>(ref T value, T x, Func<T, T, T> accumulator)

Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.

public static T AccumulateAndGet<T>(ref T value, T x, method accumulator)

public static bool CompareAndSet<T>(ref T value, T expected, T update)

Compares two values for equality and, if they are equal, replaces the stored value.

public static T GetAndAccumulate<T>(ref T value, T x, Func<T, T, T> accumulator)

Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.

public static T GetAndAccumulate<T>(ref T value, T x, method accumulator)

public static T GetAndUpdate<T>(ref T value, Func<T, T> updater)

Atomically updates the stored value with the results of applying the given function, returning the original value.

public static T GetAndUpdate<T>(ref T value, method updater)

public static T UpdateAndGet<T>(ref T value, Func<T, T> updater)

Atomically updates the stored value with the results of applying the given function, returning the updated value.

public static T UpdateAndGet<T>(ref T value, method updater)