Show / Hide Table of Contents

Class Atomic

Exposes atomic operations for thread-safe scenarios.

Inheritance
object
Atomic
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class Atomic

Methods

View Source

AccumulateAndGet<T>(ref T, T, Func<T, T, T>)

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

Declaration
public static T AccumulateAndGet<T>(ref T location, T x, Func<T, T, T> accumulator)
Parameters
Type Name Description
T location

Reference to a value to be modified.

T x

Accumulator operand.

Func<T, T, T> accumulator

A side-effect-free function of two arguments.

Returns
Type Description
T

The updated value.

Type Parameters
Name Description
T
Remarks

The function is applied with the current value as its first argument, and the given update as the second argument.

View Source

AccumulateAndGet<T, TAccumulator>(ref T, T, TAccumulator)

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

Declaration
public static T AccumulateAndGet<T, TAccumulator>(ref T location, T x, TAccumulator accumulator) where TAccumulator : ISupplier<T, T, T>, allows ref struct
Parameters
Type Name Description
T location

Reference to a value to be modified.

T x

Accumulator operand.

TAccumulator accumulator

A side-effect-free function of two arguments.

Returns
Type Description
T

The updated value.

Type Parameters
Name Description
T
TAccumulator

The type implementing accumulator.

Remarks

The function is applied with the current value as its first argument, and the given update as the second argument.

View Source

FalseToTrue(ref bool)

Atomically sets true value if the current value is false.

Declaration
public static bool FalseToTrue(ref bool location)
Parameters
Type Name Description
bool location

The destination, whose value is compared with comparand and possibly replaced.

Returns
Type Description
bool

true if current value is modified successfully; otherwise, false.

View Source

GetAndAccumulate<T>(ref T, T, Func<T, T, T>)

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

Declaration
public static T GetAndAccumulate<T>(ref T location, T x, Func<T, T, T> accumulator)
Parameters
Type Name Description
T location

Reference to a value to be modified.

T x

Accumulator operand.

Func<T, T, T> accumulator

A side-effect-free function of two arguments.

Returns
Type Description
T

The original value.

Type Parameters
Name Description
T
Remarks

The function is applied with the current value as its first argument, and the given update as the second argument.

View Source

GetAndAccumulate<T, TAccumulator>(ref T, T, TAccumulator)

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

Declaration
public static T GetAndAccumulate<T, TAccumulator>(ref T location, T x, TAccumulator accumulator) where TAccumulator : ISupplier<T, T, T>, allows ref struct
Parameters
Type Name Description
T location

Reference to a value to be modified.

T x

Accumulator operand.

TAccumulator accumulator

A side-effect-free function of two arguments.

Returns
Type Description
T

The original value.

Type Parameters
Name Description
T
TAccumulator

The type implementing accumulator.

Remarks

The function is applied with the current value as its first argument, and the given update as the second argument.

View Source

GetAndNegate(ref bool)

Negates currently stored value atomically.

Declaration
public static bool GetAndNegate(ref bool location)
Parameters
Type Name Description
bool location

Reference to a value to be modified.

Returns
Type Description
bool

The original value before negation.

View Source

GetAndUpdate<T>(ref T, Func<T, T>)

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

Declaration
public static T GetAndUpdate<T>(ref T location, Func<T, T> updater)
Parameters
Type Name Description
T location

Reference to a value to be modified.

Func<T, T> updater

A side-effect-free function.

Returns
Type Description
T

The original value.

Type Parameters
Name Description
T
View Source

GetAndUpdate<T, TUpdater>(ref T, TUpdater)

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

Declaration
public static T GetAndUpdate<T, TUpdater>(ref T location, TUpdater updater) where TUpdater : ISupplier<T, T>, allows ref struct
Parameters
Type Name Description
T location

Reference to a value to be modified.

TUpdater updater

A side-effect-free function.

Returns
Type Description
T

The original value.

Type Parameters
Name Description
T
TUpdater

The type implementing updater.

View Source

IsAtomic<T>()

Determines that write to the location in the memory of type T is atomic.

Declaration
public static bool IsAtomic<T>()
Returns
Type Description
bool

true if write is atomic; otherwise, false.

Type Parameters
Name Description
T
View Source

NegateAndGet(ref bool)

Negates currently stored value atomically.

Declaration
public static bool NegateAndGet(ref bool location)
Parameters
Type Name Description
bool location

Reference to a value to be modified.

Returns
Type Description
bool

Negation result.

View Source

Read(ref readonly double)

Reads atomically the value from the specified location in the memory.

Declaration
[CLSCompliant(false)]
public static double Read(ref readonly double location)
Parameters
Type Name Description
double location

The location of the value.

Returns
Type Description
double

The value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

View Source

Read(ref readonly long)

Reads atomically the value from the specified location in the memory.

Declaration
public static long Read(ref readonly long location)
Parameters
Type Name Description
long location

The location of the value.

Returns
Type Description
long

The value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

View Source

Read(ref readonly ulong)

Reads atomically the value from the specified location in the memory.

Declaration
[CLSCompliant(false)]
public static ulong Read(ref readonly ulong location)
Parameters
Type Name Description
ulong location

The location of the value.

Returns
Type Description
ulong

The value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

View Source

TrueToFalse(ref bool)

Atomically sets false value if the current value is true.

Declaration
public static bool TrueToFalse(ref bool location)
Parameters
Type Name Description
bool location

The destination, whose value is compared with comparand and possibly replaced.

Returns
Type Description
bool

true if current value is modified successfully; otherwise, false.

View Source

UpdateAndGet<T>(ref T, Func<T, T>)

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

Declaration
public static T UpdateAndGet<T>(ref T location, Func<T, T> updater)
Parameters
Type Name Description
T location

Reference to a value to be modified.

Func<T, T> updater

A side-effect-free function.

Returns
Type Description
T

The updated value.

Type Parameters
Name Description
T
View Source

UpdateAndGet<T, TUpdater>(ref T, TUpdater)

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

Declaration
public static T UpdateAndGet<T, TUpdater>(ref T location, TUpdater updater) where TUpdater : ISupplier<T, T>, allows ref struct
Parameters
Type Name Description
T location

Reference to a value to be modified.

TUpdater updater

A side-effect-free function.

Returns
Type Description
T

The updated value.

Type Parameters
Name Description
T
TUpdater

The type implementing updater.

View Source

Write(ref double, double)

Writes atomically the value at the specified location in the memory.

Declaration
[CLSCompliant(false)]
public static void Write(ref double location, double value)
Parameters
Type Name Description
double location

The location of the value.

double value

The desired value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

View Source

Write(ref long, long)

Writes atomically the value at the specified location in the memory.

Declaration
public static void Write(ref long location, long value)
Parameters
Type Name Description
long location

The location of the value.

long value

The desired value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

View Source

Write(ref ulong, ulong)

Writes atomically the value at the specified location in the memory.

Declaration
[CLSCompliant(false)]
public static void Write(ref ulong location, ulong value)
Parameters
Type Name Description
ulong location

The location of the value.

ulong value

The desired value at the specified location.

Remarks

This method works correctly on 32-bit and 64-bit architectures.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾