Soenneker.Atomics.Ints
11.0.70
Prefix Reserved
dotnet add package Soenneker.Atomics.Ints --version 11.0.70
NuGet\Install-Package Soenneker.Atomics.Ints -Version 11.0.70
<PackageReference Include="Soenneker.Atomics.Ints" Version="11.0.70" />
<PackageVersion Include="Soenneker.Atomics.Ints" Version="11.0.70" />
<PackageReference Include="Soenneker.Atomics.Ints" />
paket add Soenneker.Atomics.Ints --version 11.0.70
#r "nuget: Soenneker.Atomics.Ints, 11.0.70"
#:package Soenneker.Atomics.Ints@11.0.70
#addin nuget:?package=Soenneker.Atomics.Ints&version=11.0.70
#tool nuget:?package=Soenneker.Atomics.Ints&version=11.0.70
Soenneker.Atomics.Ints
A lightweight atomic int wrapper implemented as a class. Internally delegates to ValueAtomicInt for the atomic operations.
Install
dotnet add package Soenneker.Atomics.Ints
Usage
using Soenneker.Atomics.Ints;
var activeRequests = new AtomicInt();
int current = activeRequests.Increment();
try
{
await HandleRequest();
}
finally
{
activeRequests.Decrement();
}
Return values distinguish the get-and-update and update-and-get families:
int previous = counter.GetAndAdd(5);
int current = counter.AddAndGet(5);
Use SetIfGreater or SetIfLess for a retrying atomic maximum/minimum update. TrySetIfGreater and TrySetIfLess attempt one compare-and-exchange only and can return false after losing a race; they are appropriate when the caller does not require a retry.
Update and Accumulate may invoke their delegate more than once while retrying a compare-and-exchange. Keep those delegates fast and free of side effects.
What you get
AtomicInt— A lightweight atomicintwrapper implemented as aclass. Internally delegates toValueAtomicIntfor the atomic operations.
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
AtomicInt.Value |
Gets or sets the current value. | Gets or sets the current value. |
AtomicInt.Read() |
Reads the current value using acquire semantics. | The current value observed with acquire memory-ordering semantics. |
AtomicInt.Exchange(value) |
Atomically replaces the current value with value and returns the previous value. |
The value that was stored before the atomic update. |
AtomicInt.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. |
AtomicInt.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. |
AtomicInt.Increment() |
Atomically increments the value and returns the incremented value. | The incremented value. |
AtomicInt.Decrement() |
Atomically decrements the value and returns the decremented value. | The decremented value. |
AtomicInt.Add(delta) |
Atomically adds delta and returns the resulting value. |
The resulting value. |
AtomicInt.GetAndIncrement() |
Atomically increments the value and returns the previous value. | The value that was stored before the atomic update. |
AtomicInt.GetAndDecrement() |
Atomically decrements the value and returns the previous value. | The value that was stored before the atomic update. |
AtomicInt.GetAndAdd(delta) |
Atomically adds delta and returns the previous value. |
The value that was stored before the atomic update. |
AtomicInt.AddAndGet(delta) |
Atomically adds delta and returns the resulting value. |
The resulting value. |
AtomicInt.IncrementAndGet() |
Atomically increments the value and returns the resulting value. | The resulting value. |
AtomicInt.DecrementAndGet() |
Atomically decrements the value and returns the resulting value. | The resulting value. |
AtomicInt.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. |
AtomicInt.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. |
AtomicInt.SetIfGreater(value) |
Sets the value to value if it is greater than the current value, returning the effective value. |
The effective value. |
AtomicInt.SetIfLess(value) |
Sets the value to value if it is less than the current value, returning the effective value. |
The effective value. |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Atomics.ValueInts (>= 11.0.42)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.70 | 74 | 11/11/2026 |
| 11.0.69 | 72 | 11/11/2026 |
| 11.0.68 | 114 | 11/3/2026 |
| 11.0.67 | 112 | 10/27/2026 |
| 11.0.66 | 99 | 10/26/2026 |
| 11.0.65 | 97 | 10/26/2026 |
| 11.0.64 | 94 | 10/26/2026 |
| 4.0.63 | 125 | 10/15/2026 |
| 4.0.62 | 102 | 10/14/2026 |
| 4.0.61 | 95 | 10/14/2026 |
| 4.0.60 | 104 | 10/14/2026 |
| 4.0.57 | 108 | 10/13/2026 |
| 4.0.54 | 106 | 10/13/2026 |
| 4.0.53 | 105 | 10/12/2026 |
| 4.0.51 | 99 | 10/12/2026 |
| 4.0.50 | 114 | 10/11/2026 |
| 4.0.49 | 107 | 10/11/2026 |
| 4.0.48 | 155 | 9/24/2026 |
| 4.0.47 | 113 | 9/24/2026 |
| 4.0.46 | 1,263 | 9/15/2026 |
Updated Soenneker.Atomics.ValueInts to 11.0.42