Soenneker.Atomics.ValueInts
4.0.25
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Atomics.ValueInts --version 4.0.25
NuGet\Install-Package Soenneker.Atomics.ValueInts -Version 4.0.25
<PackageReference Include="Soenneker.Atomics.ValueInts" Version="4.0.25" />
<PackageVersion Include="Soenneker.Atomics.ValueInts" Version="4.0.25" />
<PackageReference Include="Soenneker.Atomics.ValueInts" />
paket add Soenneker.Atomics.ValueInts --version 4.0.25
#r "nuget: Soenneker.Atomics.ValueInts, 4.0.25"
#:package Soenneker.Atomics.ValueInts@4.0.25
#addin nuget:?package=Soenneker.Atomics.ValueInts&version=4.0.25
#tool nuget:?package=Soenneker.Atomics.ValueInts&version=4.0.25
Soenneker.Atomics.ValueInts
A lightweight, allocation-free atomic int struct backed by Volatile and Interlocked operations. Intended for use as a private field / inline synchronization primitive. Because this is a mutable struct, avoid copying it (e.g., returning it from properties or storing it in collections where it may be copied by value).
Install
dotnet add package Soenneker.Atomics.ValueInts
What you get
ValueAtomicInt— A lightweight, allocation-free atomicintstruct backed byVolatileandInterlockedoperations. Intended for use as a private field / inline synchronization primitive. Because this is a mutablestruct, avoid copying it (e.g., returning it from properties or storing it in collections where it may be copied by value).
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
ValueAtomicInt.Value |
Gets or sets the current value. | Gets or sets the current value. |
ValueAtomicInt.Read() |
Reads the current value using acquire semantics. | The current value observed with acquire memory-ordering semantics. |
ValueAtomicInt.Exchange(value) |
Atomically replaces the current value with value and returns the previous value. |
The value that was stored before the atomic update. |
ValueAtomicInt.CompareExchange(value, comparand) |
Atomically sets the value to value if the current value equals comparand. Returns the original value. |
The value observed before the compare-and-exchange attempt. |
ValueAtomicInt.TryCompareExchange(value, comparand) |
Attempts to set the value to value if the current value equals comparand. |
true if the requested update was applied; otherwise, false. |
ValueAtomicInt.Increment() |
Atomically increments the value and returns the incremented value. | The incremented value. |
ValueAtomicInt.Decrement() |
Atomically decrements the value and returns the decremented value. | The decremented value. |
ValueAtomicInt.Add(delta) |
Atomically adds delta and returns the resulting value. |
The resulting value. |
ValueAtomicInt.Or(mask) |
Performs an atomic bitwise OR operation between the current value and the specified mask, updating the value in a thread-safe manner. | The new value after the bitwise OR operation has been applied. |
ValueAtomicInt.And(mask) |
Performs an atomic bitwise AND operation between the current value and the specified mask. | The new value resulting from the bitwise AND operation. |
ValueAtomicInt.GetAndIncrement() |
Atomically increments the value and returns the previous value. | The value that was stored before the atomic update. |
ValueAtomicInt.GetAndDecrement() |
Atomically decrements the value and returns the previous value. | The value that was stored before the atomic update. |
ValueAtomicInt.GetAndAdd(delta) |
Atomically adds delta and returns the previous value. |
The value that was stored before the atomic update. |
ValueAtomicInt.AddAndGet(delta) |
Atomically adds delta and returns the resulting value. |
The resulting value. |
ValueAtomicInt.IncrementAndGet() |
Atomically increments the value and returns the resulting value. | The resulting value. |
ValueAtomicInt.DecrementAndGet() |
Atomically decrements the value and returns the resulting value. | The resulting value. |
ValueAtomicInt.TrySetIfGreater(value) |
Attempts to set the value to value if it is greater than the current value. |
true if the requested update was applied; otherwise, false. |
ValueAtomicInt.TrySetIfLess(value) |
Attempts to set the value to value if it is less than the current value. |
true if the requested update was applied; otherwise, false. |
Important behavior
ValueAtomicInt.Or(mask): This method is thread-safe and uses atomic operations to ensure that the update is performed without interference from other threads.ValueAtomicInt.And(mask): This method is thread-safe and uses interlocked operations to ensure atomicity. It can be used safely in multi-threaded scenarios to update the value without race conditions.ValueAtomicInt.VolatileWrite(value): Use this method to update the field in multithreaded scenarios where it is important that the most recent value is observed by all threads. This method provides a memory barrier to prevent certain types of reordering by the compiler or processor.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Soenneker.Atomics.ValueInts:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.BackgroundQueue
A high-performance background Task/ValueTask queue |
|
|
Soenneker.Asyncs.Locks
The fastest .NET async lock. |
|
|
Soenneker.Atomics.ValueNullableBools
A lightweight, allocation-free atomic nullable boolean struct implemented on top of an inline ValueAtomicInt |
|
|
Soenneker.Atomics.NullableBools
A lock free atomic nullable boolean. |
|
|
Soenneker.Atomics.Ints
A thread-safe int implemented on top of Interlocked/Volatile operations. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.29 | 20,145 | 9/15/2026 |
| 4.0.28 | 88,175 | 9/12/2026 |
| 4.0.27 | 32,953 | 9/12/2026 |
| 4.0.26 | 343,042 | 8/29/2026 |
| 4.0.25 | 102 | 8/29/2026 |
| 4.0.24 | 96 | 8/29/2026 |
| 4.0.23 | 423,036 | 7/27/2026 |
| 4.0.22 | 192,934 | 7/16/2026 |
| 4.0.21 | 261,789 | 6/19/2026 |
| 4.0.20 | 252,830 | 6/5/2026 |
| 4.0.19 | 127 | 6/5/2026 |
| 4.0.18 | 328,500 | 4/22/2026 |
| 4.0.16 | 289,653 | 3/12/2026 |
| 4.0.15 | 140 | 3/12/2026 |
| 4.0.14 | 144 | 3/12/2026 |
| 4.0.13 | 4,004 | 3/12/2026 |
| 4.0.12 | 90,123 | 3/10/2026 |
| 4.0.11 | 50,015 | 3/9/2026 |
| 4.0.10 | 148 | 3/9/2026 |
| 4.0.9 | 134 | 3/9/2026 |
Improve README usability and API guidance