Is there any kind of type built in type that removes the need to manually handle the thread-safety of primitive types, if not could it be possible to have a generic class implementation like the following
Proposed API
public class Atomic<T> where T : struct
{
public T Value { get; }
public void Update(T value);
public void Update(Func<T, T> updateFunc);
}
Example Usage
var counter = new Atomic<int>(0);
counter.Update(5);
counter.Update(x => x + 1);
Console.WriteLine(counter.Value);
Is there any kind of type built in type that removes the need to manually handle the thread-safety of primitive types, if not could it be possible to have a generic class implementation like the following
Proposed API
Example Usage