RobustCounter

Namespace: SnowBank.Numerics · class

Isolated counter that will not introduce false-sharing between concurrent threads

Constructors

RobustCounter

RobustCounter()

Constructs a new RobustCounter, initialized to 0

RobustCounter(int initialValue)

Constructs a new RobustCounter with the given initial value

Methods

SafeRead

int SafeRead()

Read the value from outside

UnsafeIncrement

int UnsafeIncrement()

Increment from inside the worker thread, when no one else is expected to write to this counter

Returns: Incremented value

new RobustCounter(42).Increment() == 43

UnsafeRead

int UnsafeRead()

Read the value from inside the worker thread, when no one else is expected to write to this counter

UnsafeReset

void UnsafeReset()

Reset the value from inside the worker thread, when no one else is expected to write to this counter