Soenneker.Atomics.ValueBools
4.0.44
Prefix Reserved
dotnet add package Soenneker.Atomics.ValueBools --version 4.0.44
NuGet\Install-Package Soenneker.Atomics.ValueBools -Version 4.0.44
<PackageReference Include="Soenneker.Atomics.ValueBools" Version="4.0.44" />
<PackageVersion Include="Soenneker.Atomics.ValueBools" Version="4.0.44" />
<PackageReference Include="Soenneker.Atomics.ValueBools" />
paket add Soenneker.Atomics.ValueBools --version 4.0.44
#r "nuget: Soenneker.Atomics.ValueBools, 4.0.44"
#:package Soenneker.Atomics.ValueBools@4.0.44
#addin nuget:?package=Soenneker.Atomics.ValueBools&version=4.0.44
#tool nuget:?package=Soenneker.Atomics.ValueBools&version=4.0.44
Soenneker.Atomics.ValueBools
A one-byte, allocation-free atomic boolean struct using .NET 10 byte-sized Interlocked and Volatile operations (0 = false, 1 = true).
Install
dotnet add package Soenneker.Atomics.ValueBools
Usage
Keep the mutable struct in a field so every operation addresses the same storage:
using Soenneker.Atomics.ValueBools;
public sealed class Worker
{
private ValueAtomicBool _stopping;
public bool RequestStop() => _stopping.TrySetTrue();
public bool IsStopping => _stopping.Read();
}
Do not expose it through a value-returning property, pass it by value, or store it in an API that copies structs. A copy contains independent atomic state; changes to the copy do not update the original field. Use the reference-type AtomicBool package when the state itself must be passed between objects.
Individual operations are atomic, but a read followed by a write is not one conditional operation. Use CompareAndSet, TrySetTrue, or TrySetFalse for state transitions.
Use VolatileWrite when a release write is sufficient, such as publishing a flag whose writers are already serialized.
Write and the Value setter retain their interlocked exchanges and full memory fences.
The struct occupies one byte of managed storage, matching bool. Enclosing object sizes still depend on padding and alignment.
What you get
ValueAtomicBool— A one-byte, allocation-free atomic boolean struct using .NET 10 byte-sizedInterlockedandVolatileoperations (0 = false, 1 = true).
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
ValueAtomicBool.Read() |
Reads the current value of the atomic boolean. | true if the current value is true; otherwise false. |
ValueAtomicBool.Write(value) |
Writes a new value to the atomic boolean. | This operation performs an interlocked exchange with a full memory fence. |
ValueAtomicBool.VolatileWrite(value) |
Publishes a value with release ordering. | Avoids the full fence of Write; pair with an acquire read. |
ValueAtomicBool.Exchange(value) |
Atomically replaces the current value with value and returns the previous value. |
The value that was stored prior to the exchange. |
ValueAtomicBool.CompareAndSet(expected, newValue) |
Atomically sets the value to newValue if the current value equals expected. |
true if the value was updated; otherwise false. |
ValueAtomicBool.Value |
Gets or sets the current value of the atomic boolean. | The getter performs an atomic read with acquire semantics. The setter performs an interlocked exchange with a full memory fence. |
ValueAtomicBool.TrySetTrue() |
Attempts to atomically transition the value from false to true. |
true if the value was updated; false if it was already true. |
ValueAtomicBool.TrySetFalse() |
Attempts to atomically transition the value from true to false. |
true if the value was updated; false if it was already false. |
ValueAtomicBool.ToString() |
Returns a string representation of the current value. | Returns string. |
Important behavior
ValueAtomicBool: Reads establish acquire semantics and writes establish release semantics, making this type suitable for visibility signaling and safe publication between threads. This is a mutablestructintended for use as a private field or inline synchronization primitive. Avoid copying this type, returning it from properties, or using it through interfaces, as doing so will create independent copies of the atomic state.ValueAtomicBool.Write(value): This operation performs an interlocked exchange with a full memory fence.ValueAtomicBool.Value: The getter performs an atomic read with acquire semantics. The setter performs an interlocked exchange with a full memory fence.ValueAtomicBool.TrySetTrue(): This method performs a single compare-and-exchange operation and does not spin or retry.ValueAtomicBool.TrySetFalse(): This method performs a single compare-and-exchange operation and does not spin or retry.
| 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 (14)
Showing the top 5 NuGet packages that depend on Soenneker.Atomics.ValueBools:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.AsyncSingleton
An externally initializing singleton that uses double-check asynchronous locking, with optional async and sync disposal |
|
|
Soenneker.Utils.Logger
Builds cached Microsoft loggers backed by Serilog and exposes a shared runtime level switch. |
|
|
Serilog.Sinks.XUnit.Injectable
The injectable, xUnit test output sink for Serilog |
|
|
Soenneker.Dictionaries.SingletonKeys
An externally initializing singleton dictionary that uses double-check asynchronous locking, with optional async and sync disposal |
|
|
Soenneker.Blazor.Utils.ModuleImport
A Blazor utility library assisting with asynchronous module loading |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.44 | 30,824 | 9/15/2026 |
| 4.0.43 | 57 | 9/15/2026 |
| 4.0.42 | 277 | 9/15/2026 |
| 4.0.41 | 83,002 | 9/12/2026 |
| 4.0.40 | 33,590 | 9/12/2026 |
| 4.0.39 | 6,423 | 9/12/2026 |
| 4.0.38 | 339,529 | 8/30/2026 |
| 4.0.37 | 1,812 | 8/29/2026 |
| 4.0.36 | 4,573 | 8/29/2026 |
| 4.0.35 | 417,593 | 7/28/2026 |
| 4.0.34 | 7,121 | 7/28/2026 |
| 4.0.33 | 180,421 | 7/16/2026 |
| 4.0.32 | 35,246 | 7/16/2026 |
| 4.0.31 | 243,835 | 6/19/2026 |
| 4.0.30 | 22,291 | 6/18/2026 |
| 4.0.29 | 238,554 | 6/5/2026 |
| 4.0.28 | 640 | 6/5/2026 |
| 4.0.27 | 125 | 6/5/2026 |
| 4.0.26 | 322,471 | 4/22/2026 |
| 4.0.25 | 7,381 | 4/22/2026 |
-> 1 byte