Class Atomic
Exposes atomic operations for thread-safe scenarios.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class Atomic
Methods
View SourceAccumulateAndGet<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.
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.
FalseToTrue(ref bool)
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. |
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.
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.
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. |
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 |
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. |
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 |
Type Parameters
| Name | Description |
|---|---|
| T |
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. |
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.
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.
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.
TrueToFalse(ref bool)
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. |
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 |
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. |
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.
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.
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.