Soenneker.Atomics.Longs 11.0.38

Prefix Reserved
dotnet add package Soenneker.Atomics.Longs --version 11.0.38
                    
NuGet\Install-Package Soenneker.Atomics.Longs -Version 11.0.38
                    
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.Longs" Version="11.0.38" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Atomics.Longs" Version="11.0.38" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Atomics.Longs" />
                    
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.Longs --version 11.0.38
                    
#r "nuget: Soenneker.Atomics.Longs, 11.0.38"
                    
#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.Longs@11.0.38
                    
#: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.Longs&version=11.0.38
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Atomics.Longs&version=11.0.38
                    
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.Longs

A lightweight, allocation-free atomic long 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.Longs

Usage

using Soenneker.Atomics.Longs;

var bytesProcessed = new AtomicLong();

bytesProcessed.Add(buffer.Length);
long snapshot = bytesProcessed.Read();

Use SetIfGreater to retain a high-water mark under concurrency:

peakQueueDepth.SetIfGreater(currentQueueDepth);

TrySetIfGreater and TrySetIfLess perform one compare-and-exchange attempt; the retrying SetIfGreater and SetIfLess variants are preferable when the maximum or minimum must eventually reflect the supplied candidate.

Update and Accumulate run a compare-and-exchange loop and may call their delegate multiple times. The delegate must not perform logging, I/O, mutation, or other side effects.

All members operate atomically on this counter, but several separate calls are not one transaction. Use a lock when multiple values or multi-step invariants must change together.

What you get

  • AtomicLong — A lightweight, allocation-free atomic long 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).

API at a glance

API What it does Result / important behavior
AtomicLong.Value Gets or sets the current value. Gets or sets the current value.
AtomicLong.Read() Reads the current value using acquire semantics. The current value observed with acquire memory-ordering semantics.
AtomicLong.Exchange(value) Atomically replaces the current value with value and returns the previous value. The value that was stored before the atomic update.
AtomicLong.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.
AtomicLong.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.
AtomicLong.Increment() Atomically increments the value and returns the incremented value. The incremented value.
AtomicLong.Decrement() Atomically decrements the value and returns the decremented value. The decremented value.
AtomicLong.Add(delta) Atomically adds delta and returns the resulting value. The resulting value.
AtomicLong.GetAndIncrement() Atomically increments the value and returns the previous value. The value that was stored before the atomic update.
AtomicLong.GetAndDecrement() Atomically decrements the value and returns the previous value. The value that was stored before the atomic update.
AtomicLong.GetAndAdd(delta) Atomically adds delta and returns the previous value. The value that was stored before the atomic update.
AtomicLong.AddAndGet(delta) Atomically adds delta and returns the resulting value. The resulting value.
AtomicLong.IncrementAndGet() Atomically increments the value and returns the resulting value. The resulting value.
AtomicLong.DecrementAndGet() Atomically decrements the value and returns the resulting value. The resulting value.
AtomicLong.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.
AtomicLong.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.
AtomicLong.SetIfGreater(value) Sets the value to value if it is greater than the current value, returning the effective value. The effective value.
AtomicLong.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.
  • net11.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Soenneker.Atomics.Longs:

Package Downloads
Soenneker.Blazor.Utils.Session

A Blazor utility for access-token caching and optional idle-timeout navigation

Soenneker.Blazor.Utils.Ids

A lightweight ID generator for consistent identity across the UI for Blazor components.

Soenneker.Sets.Concurrent.SlidingWindow

A high-throughput, thread-safe set whose bucketed entries automatically expire after a fixed time window.

Soenneker.Sets.Concurrent.Bounded

A high-performance bounded concurrent set for .NETe

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.38 4,184 11/11/2026
11.0.37 19,141 10/26/2026
4.0.36 10,475 10/15/2026
4.0.35 622 10/14/2026
4.0.34 110 10/14/2026
4.0.33 2,221 10/13/2026
4.0.30 834 10/12/2026
4.0.29 550 10/12/2026
4.0.28 4,846 10/11/2026
4.0.27 21,235 9/24/2026
4.0.26 7,845 9/15/2026
4.0.25 1,899 9/12/2026
4.0.24 508 9/12/2026
4.0.23 4,792 8/29/2026
4.0.22 121 8/29/2026
4.0.21 132 8/29/2026
4.0.20 5,167 7/27/2026
4.0.19 2,446 7/16/2026
4.0.18 3,600 6/19/2026
4.0.17 3,885 6/5/2026
Loading failed

Upgrade .NET 11 release candidates to stable