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
<PackageReference Include="Soenneker.Atomics.Longs" Version="11.0.38" />
<PackageVersion Include="Soenneker.Atomics.Longs" Version="11.0.38" />
<PackageReference Include="Soenneker.Atomics.Longs" />
paket add Soenneker.Atomics.Longs --version 11.0.38
#r "nuget: Soenneker.Atomics.Longs, 11.0.38"
#:package Soenneker.Atomics.Longs@11.0.38
#addin nuget:?package=Soenneker.Atomics.Longs&version=11.0.38
#tool nuget:?package=Soenneker.Atomics.Longs&version=11.0.38
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 atomiclongbacked 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 |
|---|---|---|
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
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 |
Upgrade .NET 11 release candidates to stable