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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Atomics.Ints" Version="11.0.70" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Atomics.Ints" Version="11.0.70" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Atomics.Ints" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Atomics.Ints --version 11.0.70
                    
#r "nuget: Soenneker.Atomics.Ints, 11.0.70"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Atomics.Ints@11.0.70
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Atomics.Ints&version=11.0.70
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Atomics.Ints&version=11.0.70
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 atomic int wrapper implemented as a class. Internally delegates to ValueAtomicInt for 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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Updated Soenneker.Atomics.ValueInts to 11.0.42