Soenneker.Atomics.Strings
4.0.19
Prefix Reserved
dotnet add package Soenneker.Atomics.Strings --version 4.0.19
NuGet\Install-Package Soenneker.Atomics.Strings -Version 4.0.19
<PackageReference Include="Soenneker.Atomics.Strings" Version="4.0.19" />
<PackageVersion Include="Soenneker.Atomics.Strings" Version="4.0.19" />
<PackageReference Include="Soenneker.Atomics.Strings" />
paket add Soenneker.Atomics.Strings --version 4.0.19
#r "nuget: Soenneker.Atomics.Strings, 4.0.19"
#:package Soenneker.Atomics.Strings@4.0.19
#addin nuget:?package=Soenneker.Atomics.Strings&version=4.0.19
#tool nuget:?package=Soenneker.Atomics.Strings&version=4.0.19
Soenneker.Atomics.Strings
A lock-free, thread-safe wrapper for atomically publishing and reading a string reference. Useful for shared string state and one-time (or racing) initialization without locks.
Install
dotnet add package Soenneker.Atomics.Strings
Usage
Publish a value only when no value exists:
using Soenneker.Atomics.Strings;
var currentEndpoint = new AtomicString();
if (currentEndpoint.TrySet("https://api.example.com"))
{
// This caller won the null-to-value transition.
}
string? endpoint = currentEndpoint.Get();
GetOrAdd returns the already-published value or creates a candidate:
string instanceId = id.GetOrAdd(CreateInstanceId);
Under contention, multiple callers can run the factory; only one string is published and every caller returns the winner. Keep the factory side-effect free. It must not return null.
CompareExchange compares string references, not string contents. Equal strings held by different object references do not satisfy the comparand check. Use TrySet, Exchange, or an application-level loop when content equality is required.
What you get
AtomicString— A lock-free, thread-safe wrapper for atomically publishing and reading astringreference. Useful for shared string state and one-time (or racing) initialization without locks.
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
AtomicString.Get() |
Returns the current value (may be null). | The current value. |
AtomicString.Value |
Returns the current value (may be null). | Returns the current value (may be null). |
AtomicString.HasValue |
Returns true when a non-null value has been published. | Returns true when a non-null value has been published. |
AtomicString.Exchange(value) |
Atomically sets the value and returns the previous value (may be null). | The value that was stored before the atomic update. |
AtomicString.Clear() |
Clears the value (sets to null) and returns the previous value (may be null). | The value that was stored before the atomic update. |
AtomicString.TrySet(value) |
Attempts to set the value only if the current value is null. Returns true if the caller won the race and published value. |
true if the requested update was applied; otherwise, false. |
AtomicString.TrySetIfNullOrEmpty(value) |
Attempts to set the value only if the current value is null or empty. Returns true if the value was set by this call. | true if the requested update was applied; otherwise, false. |
AtomicString.CompareExchange(value, comparand) |
Atomically replaces the value if the current value reference equals comparand. Returns the original value (may be null). |
The value observed before the compare-and-exchange attempt. |
AtomicString.TryCompareExchange(value, comparand) |
Atomically replaces the value if the current value reference equals comparand. Returns true if the exchange occurred. |
true if atomically replaces the value if the current value reference equals . Returns true if the exchange occurred; otherwise, false. |
AtomicString.GetOrAdd(factory) |
Returns the current value if present; otherwise computes a value, publishes it (best-effort), and returns the published value. | The current value. |
| 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 (2)
Showing the top 2 NuGet packages that depend on Soenneker.Atomics.Strings:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Environment
A utility library for useful environment related functionality |
|
|
Soenneker.Utils.Paths.Resources
Resolves Resources directories across local, Azure, and GitHub Actions environments. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.19 | 44,465 | 8/29/2026 |
| 4.0.18 | 95 | 8/29/2026 |
| 4.0.17 | 86 | 8/29/2026 |
| 4.0.16 | 83,486 | 7/28/2026 |
| 4.0.15 | 32,140 | 7/16/2026 |
| 4.0.14 | 46,222 | 6/19/2026 |
| 4.0.13 | 45,252 | 6/5/2026 |
| 4.0.12 | 55,508 | 4/22/2026 |
| 4.0.10 | 48,722 | 3/12/2026 |
| 4.0.9 | 273 | 3/12/2026 |
| 4.0.8 | 120 | 3/12/2026 |
| 4.0.7 | 2,667 | 3/12/2026 |
| 4.0.6 | 13,886 | 3/10/2026 |
| 4.0.5 | 4,949 | 3/9/2026 |
| 4.0.4 | 130 | 3/9/2026 |
| 4.0.3 | 1,537 | 3/9/2026 |
| 4.0.2 | 14,497 | 3/4/2026 |
| 4.0.1 | 61,177 | 1/8/2026 |
Improve README documentation